0

Is it possible to receive an event, if the user execute the "Clear Data" on the global app screen?

I create an account in my Application and save the name of the account as preference:

    AccountManager accountManager = AccountManager.get(this.context);

    Account account = new Account("my account name", "com.mchammer.cantouchthis");
    accountManager.addAccountExplicitly(account, "", null);

now, if the user clears the data, the account on the system (used for synchronisation) have to removed too...

thanks for your help

silly
  • 7,789
  • 2
  • 24
  • 37

2 Answers2

2

You can't. Your app gets FCed on Clear Data, so you can't run any code.

BUT. You can use SharedPreferences to store a boolean pref, say isAccountInitialized. You set it to true and store after your AccountManager logic has done creating the account. Then, every time you use the account for sync (or every time you launch your main activity, or your service is up do do something - this you'll have to figure out based on your app specifics) you pull the isAccountInitialized from shared prefs and if it's false and your account is present in AccountManager - that's your sign that user has executed Clear Data and it's time to remove the account from AccountManager. If it's false and there's no account - that's first launch.

// OFFTOP Nice package name :)

Ivan Bartsov
  • 19,664
  • 7
  • 61
  • 59
1

It is not possible as As soon as you press clear data. Your application process will be stopped. You can check this link for answer.

Community
  • 1
  • 1
android guy
  • 108
  • 5