How to clean data if Application crashes or is manual terminated?

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)
}

Answers


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.


Need Your Help

logistic regression R prediction function

r statistics

I have a glm model and use the following script:

Changing background position and menu bar translucence

objective-c osx cocoa

How can I change the desktop background position (one of "Fill Screen", "Fit to Screen", "Stretch to Fill Screen", "Center" or "Tile") and the menu bar translucence (on or off) from code?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.