End Android Activity

Asked 2 years ago, Updated 2 years ago, 26 views

Login on the Intro screen and proceed to the main page. A (intro) B (main)

A Activity

 Intent intent = new Intent(MyIntro.this, MainActivity.class);
 startActivity(intent);
 finish();

Once the login is complete, use the Intent to move on to the main.

If you take a picture of the log, A.OnPause() -> B.OnCreate() -> A.OnStop() - > A.OnDestroy()

This is the end of activity A. There is no problem with running the app for the first time.

However, I will end the main activity (see that B.OnDestroy() is logged)

When you run the app again, when you move on to A->B, A only goes to OnStop and OnDestroy does not work.

So when the main activity ends, activity A should not be seen, but it will be seen again.

A is Destroyed() about 2~3 times and ends well, but if you repeat after that, A remains A.

Once the app starts and activity A passes, it will not be used again, so it should be terminated normally. How do I solve this?

This is when activity A ended well and did not end well.

android

2022-09-21 20:26

1 Answers

If you no longer use "MyIntro" after the screen changes from "MyIntro" to "MainActivity," the following method seems safer than calling the finish() under "startActivity().

a. Call finish() in the Pause() function

@Override
public void onPause() {
    super.onPause();

    // // Remove the activity when its off the screen
    finish();
}

b. Set Android:noHistory property to "true" in AndroidManifest.xml.

<activity
            ...
            android:noHistory="true">
</activity>

Please refer to the site below


2022-09-21 20:26

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.