1. Introduction to the problem
First describe the problem, when we install the app, the interface will display two buttons, a completion key, an open key, click the Open key, enter the application. At this point, we click the Home button, the program will be backstage. Then click on the app icon on the desktop, a huge bug appears: The app will restart! Instead of onresume! the original interface If your app is not sensitive to multiple launches, this is fine, but if your app is sensitive to multiple launches, you have to deal with it.
2. Solution
First analysis of the cause of the problem, in the current Android system (the latest 4.4.3), click the Open button and click on the icon to start, the intent parameters are not the same, the activation mode of the activity is different, resulting in the above problems. However, because the startup parameters are set by the system, we do not change. Then we have two ideas:
1. The second start, the first start to kill
2. On the second boot, wake the activity for the first start and turn it off the second time.
Generally we choose the second type, so we have the following ideas:
1. When starting the first activity, determine whether the startup mode is started by clicking the Open key.
2. Register Broadcastreceiver in the activity that needs to be awakened, and after receiving the broadcast, call your own Onresume method.
The code added to the first activity's OnCreate method is as follows:
@Overrideprotected void OnCreate (Bundle savedinstancestate) { super.oncreate (savedinstancestate); if (Getintent (). GetFlags () & intent.flag_activity_brought_to_front)! = 0) { //Send broadcast here, wake up ACTIVITY before activation Finish (); return; } Regular Activity creation Code ...}
The problem has been solved perfectly.