简体   繁体   English

从主屏幕返回后,当前活动(具有SingleTask launchMode)不会恢复(而是调用启动器活动的onNewIntent)

[英]Current Activity (with SingleTask launchMode) does not Resume after returning from Home Screen (Calls onNewIntent for launcher Activity instead)

I have two activities, a Splash Activity (which starts up when the launcher icon is clicked), and a Map activity (which is started up later by an intent after the user logs in). 我有两个活动,一个是Splash活动(单击启动器图标时启动),另一个是Map活动(稍后在用户登录后通过意图启动)。

Sometimes when Map Activity is open, I go to the home screen, then try to resume the app where I left off a couple of seconds later. 有时,当“地图活动”打开时,我会转到主屏幕,然后尝试在几秒钟后停止的地方恢复该应用程序。 I have noticed that when I click on the launcher icon on the home screen to resume the current activity (Map Activity), I am instead re-directed to Splash activity. 我注意到,当我单击主屏幕上的启动器图标以恢复当前活动(“地图活动”)时,我被重定向到“飞溅”活动。 This goes against the behavior that is listed in the Android documentation. 这违反了Android文档中列出的行为。

According to the documentation: "When the user leaves a task by pressing the Home button, the current activity is stopped and its task goes into the background. The system retains the state of every activity in the task. If the user later resumes the task by selecting the launcher icon that began the task, the task comes to the foreground and resumes the activity at the top of the stack. 根据文档:“当用户通过按“主页”按钮离开任务时,当前活动将停止并且其任务进入后台。系统将保留任务中每个活动的状态。如果用户稍后恢复任务,通过选择启动任务的启动器图标,任务将进入前台,并在堆栈顶部恢复活动。

When map activity is running, my back stack is: 当地图活动运行时,我的后堆栈是:

---MapActivity (front-facing activity)
---SplashActivity

When I click home, I see onStop() being called in MapActivity (as expected), but when I click on the launcher activity, MapActivity is then destroyed and onNewIntent is called in SplashActivity. 当我单击主页时,我看到在MapActivity中调用了onStop()(如预期的那样),但是当我单击启动器活动时,MapActivity被破坏了,在SplashActivity中调用了onNewIntent。 Does anyone know what is causing this behavior? 有谁知道是什么导致了这种现象?

My Android Manifest is: 我的Android清单是:

 <activity
    android:name=".SplashActivity"
    android:exported="true"
    android:launchMode="singleTask">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <action android:name="com.deca.mw.SplashActivity" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
<activity
    android:name=".activity.MapActivity"
    android:hardwareAccelerated="true"
    android:launchMode="singleTask" >
    <intent-filter>
        <action android:name="android.intent.action.SEARCH" />
    </intent-filter>
</activity>

And the intent to start MapActivity is: 启动MapActivity的意图是:

   Intent intent = new Intent(appContext, MapActivity.class);
   intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
   appContext.startActivity(intent);

It's the android:launchMode="singleTask" setting in your Android manifest. 这是Android清单中的android:launchMode="singleTask"设置。 Try removing it and see if this corrects the problem you are describing. 尝试将其删除,看看是否可以解决您所描述的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM