0

I have an application with several activities.One of them is Login activity and this activity defined as MAIN in my app in manifest:

<activity
        android:name="com.company.myapp.AuthorizationMainActivity"
        android:label="@string/app_name" 
        android:launchMode="singleTask" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

The problem when my app enters background (e.g. I press home button) and then I open the app again - the Login page is showed to me. How can I show activity which was active for user at the moment application enter background?

4

3 回答 3

1

如果您不想明确将其用于特殊要求,请删除“android:launchMode="singleTask"。

“singleTask”活动允许其他活动成为其任务的一部分。它始终位于其任务的根部,但其他活动(必须是“标准”和“singleTop”活动)可以启动到该任务中。(可Android 开发人员处找到)

于 2013-05-24T19:20:31.540 回答
0

使用虚拟活动作为启动的基本活动,并在该活动中检查是否需要显示登录活动或其他活动。然后从虚拟活动开始您想要进行的特定活动。

确保noHistory在清单中将虚拟活动设置为,以便用户无法导航回它

if(needsLogIn){
    Intent i = new Intent(this,LoginActivity.class);
    startActivity(i);
}else{
    Intent i = new Intent(this,OtherActivity.class);
    startActivity(i);
}
于 2013-05-24T18:51:37.610 回答
0

删除 android:launchMode="singleTask" > singletask 活动将是根,当您按下主页按钮时,上面的所有活动都将被删除。当您删除 android:launchMode="singleTask" 时,默认行为将发生,即当您按下主页按钮然后再次启动时,它将从您离开的位置打开活动。看看链接http://developer.android.com/guide/components/tasks-and-back-stack.html

于 2013-05-24T19:26:51.267 回答