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 );
}