“This is the third day of my participation in the First Challenge 2022, for more details: First Challenge 2022”.

As mentioned, this effect is similar to the effect displayed in wechat applet, that is, after opening wechat and hopping, switch to Android multi-task window (that is, clearing memory window), you will see the following page

The wechat mini program will display two separate pages. Click “Tiaotiao.com” to enter the mini program. Click “wechat” to enter the main page of wechat chat.

How do you do that in Android?

There are two ways to do this:

The first: code dynamic implementation

Intent intent = new Intent(this, SecondActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
intent.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
startActivity(intent);
Copy the code

Add the above two flags, some articles say to use when closing

FinishAndRemoveTask ();Copy the code

Method, I did not use this method and found no problem, if there is a potential problem, please inform the people who know, thank you!!

Second: configure attributes in androidmanifest.xml

Reference link: Shows multiple activities for a single APP in the recent task list

The second method may not work for me because it requires write dead configuration, so there is no test, those who need to know can check the above address.

Note: here’s how to deal with the first method

Using the above method does achieve the effect of wechat small program multi-task window, but you will find that the two Windows in the picture at the beginning of the article is the same name, that is, the name of your APP, here is the difference with the small program, here is how to achieve this effect:

First: After testing, setting Android :lable for the activity to display in manifest.xml works, but it’s pretty much fixed and immutable.

Then: it is also possible to set the Android :icon for the activity in manifest.xml to display the “hop” text and logo.

Finally: Of course you still need to set it dynamically in the code, otherwise the fixed death is flawed for the programmer.

Call the following code in the activity you want to display to display the different text

SetTaskDescription (new ActivityManager TaskDescription (" jump jump "));Copy the code

Any smart programmer will take a look at the source code for the method and the constructor that requires parameters, so the following code is used to display both images and text and to adapt

if( Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){ setTaskDescription(new ActivityManager. TaskDescription (" jump jump ", mBitmap)); }Copy the code

Yes, you need to be above 5.0 to achieve this, and the construction of parameters will need to be passed into the Bitmap to display the image.

Final effect:

Existing problems: After adding the flag to start the activity, if you switch the task window, then you cannot return to the page that called the startActivity method before. If there is no switch, this problem will not exist, and wechat is the same, such as wechat giants have not solved (or maybe there is no need for this), but I have no way to drop.