The problem
<activity
android:name=".SplashActivity"
android:launchMode="singleTask"
android:screenOrientation="portrait"
android:theme="@style/splashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Copy the code
The problem with this line of code
android:launchMode=”singleTask”
Android :launchMode=”singleTask” Cause
The solution
Remove the android: launchMode = “singleTask”
Check out the blog for information
🙏 http://blog.csdn.net/gufeilong/article/details/72900365
First of all, let’s look at the phenomenon: 1. Click the icon to start the application for the first time, and then enter the second interface B; After pressing the home button, click the icon again to enter the page B, not A why? 2. When we open the browser to display the web page from QQ, we click the desktop icon to open the browser again and find that the web page is not just opened from QQ. Why?
The first phenomenon; Typically, when you start an application, the system will create a new Task to hold the Activity instances, one by one (if you finish before jumping to the next Task, there are none). When you click the Back button, it will display the Activity instances from the top, one by one. So when you launch A new app, you’re going to see page A when you click on the icon; When the app is in the background after clicking the home button, and then clicking the icon again after A while, the system will look for the existing Task based on the Intent. If the Task exists, the system will display it directly, so that page B is displayed instead of PAGE A. If not, the home page A is launched. The Intent information includes the launch class, action, category, and so on, all of which should be the same
Second phenomenon: when I see this problem, I do not understand, why there is this situation? I just browsed the web page on QQ with a browser. Now the browser opened from the desktop is the same application. Why not show the web page I just browsed, but open the home page of the browser for me? The Intent information includes the launch class, action, category, and so on, all of which should be the same. By the way, the startup class is different! At this time, the system no longer directly displays the corresponding Task of the application, but creates a new home page instance and displays it in the Task. This results in the abnormal interface when the app is manually installed for the first time by clicking the home button and clicking the icon. So what’s the solution? In the onCreate() method on the home page add:
if((getIntent().getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) ! =0) {
// End your activity
finish();
return;
}
Copy the code
or
// Avoid activities that re-instantiate the entry class after starting the application from the desktop
if (!this.isTaskRoot()) {
Intent intent = getIntent();
if(intent ! =null) {
String action = intent.getAction();
if (intent.hasCategory(Intent.CATEGORY_LAUNCHER) && Intent.ACTION_MAIN.equals(action)) {
finish();
return; }}}Copy the code
Verification is all right! Determine whether the Intent is to open a new task or to bring the background application to the foreground. If you find that you are not in a Task, the top Activity on the stack is not displayed.