按设备的主页键后,在应用程序图标上打开最近 activity
Open recent activity on app icon press , after pressing the home key of device
我的启动器 class 名称是 "SplashScreen"。我有两个活动 "MainActivity" 和 "MenuList"。当用户打开应用程序时,将启动 SplashScreen Activity。初始屏幕 Activity 验证并启动 MainActivity。用户通过单击 MainActivity 屏幕中的按钮打开 MenuList Activity,然后单击 MenuList Activity 中的主页按钮。当用户打开应用程序时,它应该直接打开 MenuList Activity。我进行了如下所述的更改 link。当用户在 MainActivity 中按下主页按钮时,它工作正常。当用户按下 MenuList Activity 中的主页按钮时,它不起作用。请帮助我。
屏幕流:
SplashScreen -> MainActivity -> MenuList
清单代码:
<activity
android:name=".SplashScreenActivity"
android:clearTaskOnLaunch="true"
android:launchMode="singleTask"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:windowSoftInputMode="adjustResize|stateHidden"
android:screenOrientation="portrait" />
<activity
android:name=".MenuList"
android:windowSoftInputMode="adjustResize|stateHidden"
android:screenOrientation="portrait" />
从 SplashActivity 的元素中删除 android:clearTaskOnLaunch="true"
。
事实上,这对您的 MainActivity 也不起作用 - 由于设置了此标志,每次您返回到您的应用程序时,都会清除任务堆栈并启动 SplashActivity。
我得到了我想要的结果。我做了以下修改:
清单文件:
<activity
android:name=".SplashScreenActivity"
android:launchMode="singleTask"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:windowSoftInputMode="adjustResize|stateHidden"
android:screenOrientation="portrait" />
<activity
android:name=".MenuList"
android:windowSoftInputMode="adjustResize|stateHidden"
android:screenOrientation="portrait" />
我在 SplashActivity 中添加了以下代码:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if ((getIntent().getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) != 0) {
// Activity was brought to front and not created,
// Thus finishing this will get us to the last viewed activity
finish();
return;
}
//...rest of the code
}
我的启动器 class 名称是 "SplashScreen"。我有两个活动 "MainActivity" 和 "MenuList"。当用户打开应用程序时,将启动 SplashScreen Activity。初始屏幕 Activity 验证并启动 MainActivity。用户通过单击 MainActivity 屏幕中的按钮打开 MenuList Activity,然后单击 MenuList Activity 中的主页按钮。当用户打开应用程序时,它应该直接打开 MenuList Activity。我进行了如下所述的更改 link。当用户在 MainActivity 中按下主页按钮时,它工作正常。当用户按下 MenuList Activity 中的主页按钮时,它不起作用。请帮助我。
屏幕流: SplashScreen -> MainActivity -> MenuList
清单代码:
<activity
android:name=".SplashScreenActivity"
android:clearTaskOnLaunch="true"
android:launchMode="singleTask"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:windowSoftInputMode="adjustResize|stateHidden"
android:screenOrientation="portrait" />
<activity
android:name=".MenuList"
android:windowSoftInputMode="adjustResize|stateHidden"
android:screenOrientation="portrait" />
从 SplashActivity 的元素中删除 android:clearTaskOnLaunch="true"
。
事实上,这对您的 MainActivity 也不起作用 - 由于设置了此标志,每次您返回到您的应用程序时,都会清除任务堆栈并启动 SplashActivity。
我得到了我想要的结果。我做了以下修改:
清单文件:
<activity
android:name=".SplashScreenActivity"
android:launchMode="singleTask"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:windowSoftInputMode="adjustResize|stateHidden"
android:screenOrientation="portrait" />
<activity
android:name=".MenuList"
android:windowSoftInputMode="adjustResize|stateHidden"
android:screenOrientation="portrait" />
我在 SplashActivity 中添加了以下代码:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if ((getIntent().getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) != 0) {
// Activity was brought to front and not created,
// Thus finishing this will get us to the last viewed activity
finish();
return;
}
//...rest of the code
}