Abin Mathew Abraham
Abin Mathew Abraham

Reputation: 170

How do I clear the SharedPreferences or other permanent storage of my Android app from my app program?

I need to retain some information so that I can access it when I launch my app after it is closed. I need to use that information on 'onCreate()' of my 'MainActivity'. But I need to clear/reset those information if the mobile is rebooted. So how do I know in the program if the mobile has been rebooted and the activity is launched for the first time after reboot?

Upvotes: 1

Views: 75

Answers (1)

Raghav Sood
Raghav Sood

Reputation: 82563

Listen for the BOOT_COMPLETED broadcast to know when the phone has been turned on.

Then use SharedPreferences.Editor.clear() followed by a commit() to delete all data for your app.

Upvotes: 6

Related Questions