Question

I have a kid's app for Android and there are some unique considerations for this application since the app has basically no navigation (it's for young kids). I do not want to break my app UI (which has been successful on iPhone) by adding a quit/restart button.

What I really need is fairly simple -- I want my activity/app to start clean and new every single time it starts. Whether it's an initial load or whatever -- basically any time onResume is called I want a completely fresh instance of my app.

I initially thought I could just exit/quit/finish the app when the user leaves. But I haven't found a way to do this that doesn't cause crashes on start. Also every thread/stack overflow post about that idea is filled with people wagging their fingers and saying you should never ever quit an app on android.

If I can't quit the app onExit, is there something I can do to restart my activity every time onResume is called? (or would that be an infinite loop?).

Would greatly appreciate any help!

Was it helpful?

Solution

Try starting your main activity in onResume, and clearing the activity stack:

public void onResume() {
    super.onResume();
    startActivity(new Intent(this, MainScreen.class).addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
}

maybe these aren't the correctl flags to add, but check out the other Intent flags and this could do what you want!

intent flags documentation

OTHER TIPS

Ended up getting it to work fine by calling finish() in onPause().

Again, I appreciate the advice from people saying "this is not how Android does things". I've got a pretty good understanding of the best practices at this point. This is an unusual situation for an unusual type of user.

in your reload you can try this..

onStop();
onCreate(getIntent().getExtras());
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top