Parsing Android To create a shortcut will start two application problems _android

Source: Internet
Author: User

Next, let's talk about a perfect solution.
Because the first interface is the Welcome interface, the shortcut startup interface is also welcome, and at first you suspect that the code created by the shortcut is problematic, but you don't know what the problem is. Guessing may be a shortcut to the error caused the system to create two applications, it is also the same application will have two PID, the results in the console to view the print log, the different ways to start log as follows:

Copy Code code as follows:

09-22 09:39:11.929:info/activitymanager (%): 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 (): Displayed com.android.xxx/.activity. Initactivity: +763ms

09-22 09:39:47.668:info/activitymanager (%): 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 (): Displayed com.android.xxx/.activity. Initactivity: +995ms


Finally found two PID is consistent (Initactivity is the Welcome interface activity), may be an accident, the two log comparisons will find that from the list click on the icon to start the application is the above log, through the shortcut to boot is the following log, through the comparison will find that, Starting an application with a shortcut is less cat=[android.intent.category.launcher than the other way around], so add in your code (refer to the previous code and add only the third row):
Copy Code code 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);

Again run application all OK, will not start two applications, exit also only need once, too to force! As for why it is left to the spectators you.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.