5

I have an Android application that uses Accounts to synchronize data with my server. Yesterday I noticed that, if I click Clear Data in Settings->Apps->My App, the application data is removed but the user account isn't. This leads to consistency problems in my server, since suddenly the user's data is restarted without receiving a restart message.

Is there any way to delete the Account when the user clicks Clear Data? Or at least capture the event to be able to send a message to my server.

Thanks!

braX
  • 11,506
  • 5
  • 20
  • 33
PX Developer
  • 8,065
  • 7
  • 42
  • 66

1 Answers1

2

There is two ways for you to do it..

1.Not allowing the user to clear the data..this can be done by simply mentioning the..

android:manageSpaceActivity=".ActivityOfYourChoice"

in your manifest under application tag..

2.You can deleting the accounts.it can be done using the AccountManager and the removeAccount method.

First get an instance of the AccountManager:

AccountManager am = AccountManager.get(this);

Then get a list of all accounts on the device:

Account[] accounts = am.getAccounts();
kalyan pvs
  • 14,486
  • 4
  • 41
  • 59
  • 1
    this. Combine it with Preferences. As when user clears the data, preferences get deleted with it. So if you can find preferences like username or something then delete the account. – d3m0li5h3r Oct 29 '13 at 11:02
  • @d3m0li5h3r yes..check for the preference files if they are not available delete accounts also.. – kalyan pvs Oct 29 '13 at 11:05
  • Thnak you! For now I'll just use your first option, leading the user to the activity that allows him to restart the data. – PX Developer Oct 29 '13 at 11:08