Search code examples
androidandroid-preferencesaccount

Android account preferences: How can i add an 'edit accounts' button?


I just recently implemented some custom account functionality for my app. Adding accounts works fine.

Now if i have an account created and select my accounttype in the android settings, i want to have a button there which opens an Activity or Dialog for editing accounts.

I did not find a 'clean' solution for such a button and got to the point of quirky workarounds. At the moment i am trying to create a custom preference which will not set any values, but will provide a view in the settings for which an onClickListener can be set.

However, i can not even get the simplest Preference subclasses to work; when i am using my custom Preference and then select my accounttype in the android settings, the settings sometimes just close, but most of the time i get an android error "Settings has been closed".

What would help me here is either a better way to have this button, or a pointer to why i am getting this error, or a way to debug this, because i am not getting any error messages in logcat.

My custom preference:

public class RSSSEditPreference extends CheckBoxPreference
{
    public RSSSEditPreference(final Context context, final AttributeSet attrs)
        {
        super(context, attrs);
        }
}

The preferences.xml i am using:

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
    <CheckBoxPreference
        android:key="show_password"
        android:title="@string/setup_show_password"
        android:defaultValue="false" />
    <net.roughdesign.rsss.account.RSSSEditPreference
        android:key="show_another_thing"
        android:title="@string/setup_show_password"
        android:defaultValue="false" /> 
</PreferenceScreen>

It works if i comment out my custom preference in the preferences.xml.

This is what LogCat shows for one run (installing, starting, closing, try in settings):

06-12 15:19:01.375: I/Timeline(18100): Timeline: Activity_launch_request id:net.roughdesign.rsss time:71954753
06-12 15:19:01.649: D/OpenGLRenderer(18100): Enabling debug mode 0
06-12 15:19:01.813: I/Timeline(18100): Timeline: Activity_idle id: android.os.BinderProxy@41aabb78 time:71955189
06-12 15:19:02.125: I/Timeline(18100): Timeline: Activity_idle id: android.os.BinderProxy@41aabb78 time:71955507
06-12 15:19:05.750: I/Timeline(18100): Timeline: Activity_idle id: android.os.BinderProxy@41aabb78 time:71959126
06-12 15:19:15.469: I/Timeline(18100): Timeline: Activity_idle id: android.os.BinderProxy@41aabb78 time:71968840

Solution

  • It seems LogCat somehow only displayed a small part of what was happening.
    After restarting the IDE (Eclipse), i can now see error messages in LogCat, so i can proceed.

    Furthermore, what i wanted to achieve can be done by adding an intent to a preference in the preference XML file, like described here:
    http://developer.android.com/guide/topics/ui/settings.html#Intents