awaistoor
awaistoor

Reputation: 45

SharedPreferences: how to clear all preferences when application crashes

im new in android and im using SharedPreference of android for storing some states of the buttons, lets say storing the active state and unactive state of the button in SharedPreferences. But problems occurs whenever my application crashes, i want to clear my all preferences (i.e. making the button state on default value).

so i was wondering that is there any way i can clear my app's preferences whenever my application crashes.

Thanks

Upvotes: 0

Views: 534

Answers (3)

Szymon
Szymon

Reputation: 43023

By definition, when an application crashes, it means an exception that has not been caught happened. If you're not catching this exception, you cannot do any action.

Try to analyse the cause of the crash and fix it rather than relying on crashing as a normal course of action.

Upvotes: 0

2Dee
2Dee

Reputation: 8621

I would suggest to re-write your app so it doesn't crash, an app crash is a terrible user experience ! Then handle the SharedPreferences is a safer way ...

Upvotes: 1

Dima
Dima

Reputation: 158

use the app-info of your app and clear cache or all the data!

Upvotes: 0

Related Questions