Android Home Key Point shortcut menu application restart problem [perfect solution], androidhome

Source: Internet
Author: User

Android Home Key Point shortcut menu application restart problem [perfect solution], androidhome

Preface

1. This problem has plagued me for a long time.

2. There are many solutions on the Internet, most of which are lanchModel setting. Although this can solve some problems, it cannot be completely solved, and it is not consistent with my situation.


Solution:

Solution 1:

1. If your program has a stack for activity management, you can judge whether another activity exists in the stack in onCreate of LogoActivity. If there is a stack, finish + return directly. This is OK, but it always feels unreliable.


Solution 2:

2. You may accidentally find that the original shortcut is created. The flag or intent creation method of the shortcut causes the restart.

How to create shortcuts is omitted here

View code

Public void addShortCut (){

Intent shortcut = new Intent ("com. android. launcher. action. INSTALL_SHORTCUT ");
// Set attributes
...

...

...

// Click a shortcut

The intent must be created. You cannot create it using getintent or getPackmager. getLaunchIntentFor.... If you create it like this, setflag is invalid.
Intent intent = new Intent ();

Intent. setComponent (getComponentName ());

Intent. setAction (intent. ACTION_MAIN );

Intent. addCategory (Intent. CATEGORY_LAUNCHER );

// Add this sentence

Intent. setFlags (Intent. FLAG_ACTIVITY_RESET_TASK_IF_NEEDED | Intent. FLAG_ACTIVITY_NEW_TASK );

// Set the Startup Program
Shortcut. putExtra (Intent. EXTRA_SHORTCUT_INTENT, intent );
// Broadcast notification desktop Creation
This. sendBroadcast (shortcut );
}


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.