Android App / Activity To Start Fresh Totally every time it starts or resumes?

I have an Android app for Android, and there are some unique considerations for this app, as there is no navigation in the app (this is for young children). I do not want to violate the user interface of the application (which was successful on the iPhone) by adding the quit / restart button.

What I really need is pretty simple - I want my activity / application to start clean and new every time it starts. Whether it's bootstrapping or something else - basically, anytime onResume is called, I want a completely new instance of my application.

At first it seemed to me that I could just exit / exit / end the application when the user leaves. But I did not find a way to do this, which does not cause a crash on startup. Also, each thread / stack overflow thread about this idea is filled with people wagging its fingers, and says that it should never stop the application on the android.

If I cannot exit the onExit application, is there something I can do to restart my activity every time onResume is called? (or will it be an endless loop?).

I would really appreciate any help!

+3
source share
3 answers

Try running the main event in onResumeand clear the action stack:

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

, , Intent, , !

+8

, , finish() onPause().

, , : " , Android ". . .

+4

in your reboot you can try this.

onStop();
onCreate(getIntent().getExtras());
+2
source

Source: https://habr.com/ru/post/1775730/


All Articles