Discussion on the problem of directly opening the application on the successful interface of the Android application installation

    I ran into a problem before. When the Android application clicks "Open" on the installation completion interface, opens the application, presses the home button to the desktop, and then clicks the icon to re-enter the application, the MainActivity will be instantiated repeatedly. That is, without exiting the application, when you click the icon from the Launcher to enter the application, MainActivity is displayed, and it is newly instantiated.

    The online solution to this problem is to judge isTaskRoot() in MainActivity's onCreate(), and end the Activity if the Activity is not at the bottom of the Activity stack.

    https://code.google.com/p/android/issues/detail?id=2373#c40

 

if (!isTaskRoot()) {
      finish();
      return;
}

    So what is causing this problem? First of all there is nothing wrong with our code. The problem is when the installation is complete and the application is opened.

 

There is a difference in the process of launching the default Activity of an application in     Android and launching a new Activity inside the application. Lao Luo has two blogs that show the startup process of Android Activity in great detail from source code analysis.

    Click the application icon to start the Activity process: http://blog.csdn.net/luoshengyang/article/details/6689748

    The process of starting a new Activity inside the application: http://blog.csdn.net/luoshengyang/article/details/6703247

    The process of starting a new Activity inside the application eliminates the step of creating a new process in the middle, because the new Activity is executed in the existing process and task, and there is no need to create a new process and task. When the application clicks "Open" on the installation completion interface and then clicks the icon on the desktop, the system determines that the application has not been started, and re-instantiates MainActivity.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326821647&siteId=291194637