按下设备的主键后,打开最近的应用程序图标按下活动
我的启动程序类名称为“SplashScreen”。我有两个活动“MainActivity”和“MenuList”。当用户打开应用程序时,启动SplashScreen Activity。初始屏幕活动验证并启动MainActivity。用户通过单击MainActivity屏幕上的按钮打开MenuList Activity,然后单击MenuList Activity中的home按钮。当用户打开应用程序时,应该直接打开MenuList Activity。我已经在下面的链接中提到了更改。当用户在MainActivity中按Home键时它工作正常。用户在MenuList Activity中按Home按钮时不起作用。请帮帮我。按下设备的主键后,打开最近的应用程序图标按下活动
https://stackoverflow.com/a/20815679/1517280
ScreenFlow: 闪屏 - > MainActivity - >的菜单列表
清单的代码:
<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正在启动。
我在SplashActivity中添加了以下代码。它对MainActivity工作正常 保护无效onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState);如果((getIntent()。getFlags()&Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)!= 0){ //活动被带到前面并且未被创建, //因此,完成这将使我们到最后查看的活动 完成); return; } //定期创建活动代码... } –
谢谢。它正在工作。我已经从SplashActivity –
@SrikanthReddyRamidi中删除android:clearTaskOnLaunch =“true”,然后考虑接受答案。 – Vasiliy
我得到了我想要的结果。我做了以下修改:
清单文件:
<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:从`闪屏launchMode`:
@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
}
删除这两个'安卓clearTaskOnLaunch'和'机器人'。同时删除您从链接的答案中添加的时髦代码。你不需要这些。你想要的行为是标准的Android行为。 –