Question

I have created sync adapter for android that syncs data with my server. I works fine, but now I want to be able to change my username and password without removing and adding the account again. How can I do this?

I have a login screen that has edit texts for entering username and password, but how to apply these changes to the account?

EDIT:

Found a way how to change the password:

AccountManager.get(mContext).setPassword(account, password );

where account is my account, and password is the new password.

So now my question is: HOW TO CHANGE THE USERNAME?

Was it helpful?

Solution

I can change the password with no problem, but if I want to change the username of the account I must delete and recreate the account with the new username. This deletes all data from that account and resyncs the account again from the beginning.

OTHER TIPS

AccountManager.renameAccount(Account account, String newName, AccountManagerCallback<Account> callback, Handler handler)

This has been unfortunately added only in API 21 (documentation). In previous versions, deleting and recreating the account with the new username is the only way, as mentioned in another answer.

Use an AccountAuthenticatorActivity, which you can either open from the Settings -> Accounts & Sync page inside your account, or when you try to fetch from the server and get an error indicating wrong login. Look here for details of how to set it up. Writing an Android Sync Provider: Part 1

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top