android - 当按下后退按钮时,我的应用程序会关闭最近的应用程序
问题描述
当我的活动正在运行时,如果用户按下 backPressed,活动将被关闭,并且在最近的应用程序列表中不可见。我希望它显示在最近的应用程序列表中。我怎样才能做到这一点?
@Override
public void onBackPressed() {
super.onBackPressed();
Intent i = new Intent(Intent.ACTION_MAIN);
i.addCategory(Intent.CATEGORY_HOME);
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
}
显现:
<activity
android:name=".MyActivity"
android:configChanges="mcc|mnc|locale|touchscreen
|keyboard|keyboardHidden
|navigation|orientation
|screenLayout|screenSize
|fontScale"
android:excludeFromRecents="true"
android:exported="true"
android:launchMode="singleTask"
android:screenOrientation="portrait" />
解决方案
从 AndroidManifest 中删除此行
android:excludeFromRecents="true"
或设置为假
android:excludeFromRecents="false"
推荐阅读
- arrays - 极慢的 char* 访问
- r - 选择相似的句子
- python - Python - 对列进行差异迭代
- python - 如何根据文本 tkinter 中的选择更改字体?
- c++ - 如何将结构成员指针传递给函数?
- python - 从方形网格计算像素的坐标
- python - 托管在 ECS 中的 Web 服务器出现 ERR_TIME_OUT 错误/格式错误的 HTTP 消息?
- python - Firebase-Admin 与 AWS Lambda Python
- regex - 有没有办法在 Spacy NLP 中区分带空间和不带空间的模式
- hyperledger-fabric - Hyperledger Fabric 中的链码实例化错误