Android Home key shortcut menu app restart problem "perfect solution"

Source: Internet
Author: User

Objective

1, this problem troubled me n long n

2, there are many solutions on the Internet, mostly set Lanchmodel although this can solve some problems, but can not be fully resolved, and I do not match the situation


Solution:

Programme one:

1, if your program has a management activity stack, you can start logoactivity in the OnCreate to determine that the stack is the existence of other activity if it has its own direct finish + return. This is OK, but always feel a kind of unreliable feeling.


Scenario Two:

2, inadvertently found that the original is the creation of a shortcut to the problem, the shortcut flag or intent created in a way that causes a restart.

about how to create shortcut omitted here

Look at the code

public void Addshortcut () {

Intent shortcut = new Intent ("Com.android.launcher.action.INSTALL_SHORTCUT");
Setting properties
...

...

...

Click the action of the shortcut

the intent here must be newly created, cannot use getintent or getpackmager.getlaunchintentfor ... And so on, if this creation causes Setflag to be invalid
Intent Intent = new Intent ();

Intent.setcomponent (Getcomponentname ());

Intent.setaction (Intent. Action_main);

Intent.addcategory (Intent.category_launcher);

To add this sentence

Intent.setflags (intent.flag_activity_reset_task_if_needed| Intent.flag_activity_new_task);

Setting up the Startup program
Shortcut.putextra (Intent.extra_shortcut_intent, Intent);
Broadcast Notification desktop to create
This.sendbroadcast (shortcut);
}


Android Home key shortcut menu app restart problem "perfect solution"

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.