6

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!

peter
  • 471
  • 5
  • 16
  • 1
    what do you mean with "restart" of the app ? each time when it is restarted, the kids to see what is in the "beggining" of the app ? – apps Nov 18 '10 at 21:07
  • Yes, this is exactly what I mean. The app has no navigation, it cycles through multiple games. Navigation + 3 year olds generally means frustration, avoiding it is one of the reasons we've had a hit in this market. I'm *totally* aware this isn't how you'd normally want an Android app to work, and I'd never do it this way in any other case. Anyway, it all appears to be working great now. – peter Dec 06 '10 at 21:07

3 Answers3

10

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

james
  • 26,141
  • 19
  • 95
  • 113
  • If you check the Activity lifecycle (http://developer.android.com/reference/android/app/Activity.html) you can see that if this is on the main activity, then you will fall on a booting loop. – josetapadas Jun 03 '13 at 15:59
5

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.

peter
  • 471
  • 5
  • 16
2

in your reload you can try this..

onStop();
onCreate(getIntent().getExtras());
Aaron Saunders
  • 33,180
  • 5
  • 60
  • 80