-3

When I was implementing last activity, a doubt came. My app stores and get some values from DB and SharedPreferences, so, is it possible to clean them if my App crashes or is terminated?

With terminated I mean like someone who goes in "Device Settings" and manually terminates App (or in other way). Maybe by a background check service?

EDIT - SOLVED by myself

Simply handling DefaultUncaughtExceptionHandler inside Application's onCreate:

Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread thread, final Throwable ex) {
  // here i start a new Activity in which clean and handle what i need)
}
kinghomer
  • 3,021
  • 2
  • 33
  • 56
  • I don't understand why people downvote post without saying why.... Question is not useful or clear ? – kinghomer Sep 08 '12 at 08:24
  • you ask a question without showing any code or explaining what you've tried. It is not really possible to give a concise answer. Besides, you don't even seem to take time to format your question. – Maarten Bodewes Sep 26 '12 at 19:17
  • Question doesn't need code. Please read with more attention. – kinghomer Sep 27 '12 at 10:59

3 Answers3

1

I guess the best way would to check for "garbage" data when your app first load. your app will not be notified of anything else if it crashes or the user force closes it.

Budius
  • 39,391
  • 16
  • 102
  • 144
  • Maybe i don't understand well your advice. I could check garbage data when app loaded ? Can you give me an example pls ? – kinghomer Sep 07 '12 at 16:04
  • that really depends on the data you're generating. Ps.: and I'm considering here permanently stored data (files, db, shared pref) if it's just RAM data the garbage collector will take care of it as noted by @Rag – Budius Sep 11 '12 at 09:52
0

If you manually terminate the application then garbage collector will remove all the values stored temporarily.

NewLearner
  • 116
  • 3
  • 16
  • For example... my SharedPreference is not resetted if a crash or app is terminated. So, since i can't capture when it happens, i can't clean SharedPreference file by a reset() – kinghomer Sep 07 '12 at 16:00
0

Uninstalling the app will remove all databases / files etc.

adb uninstall <package name>
Shawn Chin
  • 84,080
  • 19
  • 162
  • 191
gheese
  • 1,170
  • 1
  • 11
  • 17