Krister
Krister

Reputation: 31

Editing custom accounts

I have created my own custom account and that is working fine to add an account and to use it in the app.

I now want to be able to edit the account information instead of removing and adding an account. I have a number of fields on my account and some can be a bit lengthy, so removing and adding is rather cumbersome.

I have created the basics for this by adding my own PreferenceScreen and connected it via the android:accountPreferences in my account-authenticator XML file as per the example here: AbstractAccountAuthenticator.

In my PreferenceScreen I define an intent to open my activity that is used to enter the user data for the account.

<PreferenceScreen
    android:key="edit"
    android:title="Edit Account Details"
    android:summary="Change System ID, user name, password etc.">
    <intent
        android:action="my.app.accountmanager.UserCredentialsActivity.ACCOUNT_SETUP"
        android:targetPackage="my.app.accountmanager"
        android:targetClass="my.app.accountmanager.UserCredentialsActivity" />
</PreferenceScreen>

My issue is, how do I either pass along as extras in the intent or find the account information for the account I selected in the Settings/Accounts & Sync. It is possible to have multiple accounts of this custom account type, so I can't just search for any account of that type. I need the data from the selected account.

My thoughts have roughly been in these areas:

  1. Include something in the xml to add extras. Don't see how this can be possible.
  2. Have the target for the intent be my AccountAuthenticator class or the authenciation service, but how do I pass in that I want to edit the data? Since AbstractAccountAuthenticator has a method updateCredentials that returns a bundle with the intent to my data entry activity, that could perhaps work if I could pass in an EDIT action or something like that.
  3. Override some method somewhere to create my own intent with the account data.

I hope this is possible to do as both a Samsung app and the Dropbox app do this from the Accounts & Sync, although neither allow multiple accounts...

Upvotes: 3

Views: 963

Answers (1)

Phuah Yee Keat
Phuah Yee Keat

Reputation: 1630

I think the accountPreferences attribute in AbstractAccountAuthenticator is going to be obsolete soon. If you look at the accounts in JB, if you add multiple accounts, it is going to be displayed like this

  1. [email protected]
  2. [email protected]
  3. Preference

Instead of

  1. [email protected] -> Preference
  2. [email protected] -> Preference

And if you take a look at the Gmail app, the preferences (notifcation ringtone) for Gmail is configured within the Gmail app itself, and can't be configured from the Accounts & Settings page.

So, you should only use the accountPreferences attributes for preferences that are common to all accounts.

Upvotes: 1

Related Questions