Next we will talk about a perfect solution.
Because the first interface is a welcome interface, the shortcut startup interface is also a welcome interface. At the beginning, I suspect that there is a problem with the Code created by the shortcut, but I don't know where the problem is. A shortcut error may cause the system to create two applications. The same application has two PIDs, and the printed LOG is displayed on the console,Logs started in different ways are as follows:
Copy codeThe Code is as follows: 09:39:11, 09-22. 929: INFO/ActivityManager (61): Starting: Intent {act = android. intent. action. MAIN cat = [android. intent. category. LAUNCHER] flg = 0x10200000 cmp = com. android. xxx /. activity. initActivity} from pid 19304.
09-22 09:39:12. 876: INFO/ActivityManager (61): Displayed com. android. xxx/. activity. InitActivity: + 763 ms
09:39:47 09-22. 668: INFO/ActivityManager (61): Starting: Intent {act = android. intent. action. MAIN flg = 0x10000000 cmp = com. android. xxx /. activity. initActivity bnds = [5,392] [115,510]} from pid 19304
09-22 09:39:48. 737: INFO/ActivityManager (61): Displayed com. android. xxx/. activity. InitActivity: + 995 ms
At last, we found that the two PIDs are consistent (InitActivity is the Activity on the welcome page), which may be an accident. When we compare the two logs, we will find that the above LOG is used when we click the icon from the list to start the application, the following LOG is started through the shortcut method. After comparison, we can find that the cat = [android. intent. category. LAUNCHER], so you can add it to the Code (refer to the previous Code and add only the third line ):Copy codeThe Code is as follows: ComponentName comp = new ComponentName (this. getPackageName (), this. getPackageName () + "." + this. getLocalClassName ());
Intent intent = new Intent (Intent. ACTION_MAIN). setComponent (comp );
Intent. addCategory (Intent. CATEGORY_LAUNCHER );
Shortcut. putExtra (Intent. EXTRA_SHORTCUT_INTENT, intent );
Running the application again is okay. It won't start two applications, and it only takes one time to exit. This is awesome! As for why we leave it to the visitor.