Im building my first android game, my problem is:
When I exit from the app with my phone’s “back\exit” button, my app is closing and all the information I need is nicely saved to a preference file:
@Override
protected void onPause()
{
super.onPause();
// My pref file
SharedPreferences preferences = getSharedPreferences(PREF_FILE_NAME, 0);
SharedPreferences.Editor editor = preferences.edit();
// Put the values to the pref file
editor.putInt("CsereHolTart", CsereHolTart);
editor.putInt("melyikAct", melyikAct);
editor.putInt("Silver", Silver);
editor.putInt("Strength", Strength);
editor.putInt("Intelligence", Intelligence);
editor.putInt("Dexterity", Dexterity);
editor.putInt("Speed", Speed);
editor.putInt("Vitality", Vitality);
editor.putInt("Morale", Morale);
editor.putInt("cHp", cHp);
editor.putInt("cMp", cMp);
editor.putInt("isGame", 1);
// Commit to storage
editor.commit();
}
See? I simply use the onPause() method to put all the things I need to a preference file actually to this:
public static final String PREF_FILE_NAME = "PrefFile";
When I open the app, all the saved data is well read, and my app continues from the right pont with the valid values I saved then loaded.
THIS IS GOOD, BUT:
When I close my applicaton with my phone’s task manager, so i manually do a “force close”, it seems onPause() is just not running, or something else I dont know. So the matter is when I close my app with task manager, all the loadings are fails, it seems all the saved data is deleted. Becuse every preference is loaded to default in that way.
Can anybody tell me what should I do to solve this task manager’s force close problem?
I want to save and load everytime the user exit from the app or opens the app.
If you are in the foreground and kill the process via some sort of task manager,
onPause()will not be called.onPause()is only called when some other activity takes over the foreground.