To simulate pressing the home Key in launcher ., Launcherhome
Intent mHomeIntent = new Intent (Intent. ACTION_MAIN); mHomeIntent. addCategory (Intent. CATEGORY_HOME); mHomeIntent. addFlags (Intent. FLAG_ACTIVITY_NEW_TASK | Intent. FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); getApplicationContext (). startActivity (mHomeIntent); // use getApplicationContext
In Android, if you want to call a stack Activity moveTaskToFront, you can define a BroadcastReceiver to receive some types of Broadcast and start the Activity in onReceive. However, you must note the context parameter before startActivity. In android activity, startAcitivity cannot be used to advance itself to the front of the stack. Therefore, the context of startActivity in onReceive cannot be Activity. In addition, if the BroadcastReceiver is dynamically registered (dynamic register), the context parameter passed in onReceive is this Activity and cannot be used. A more effective way to deal with this problem is not to use this context directly, but to use context. getApplicationContext () to implement moveTaskToFront. The corresponding value to moveTaskToFront is moveTaskToBack, which is relatively simple. Activity already provides the moveTaskToBack method. Note that once this method is called, the task of the Activity will be relocated to the bottom of the stack.