Android: How to make launcher always open the main activity instead of child activity? (or otherwise)(Android:如何使启动器始终打开主活动而不是子活动?(或其他))
问题描述
我有活动 A 和 B.A 是带有 LAUNCHER 意图过滤器的活动(即当我们单击主屏幕上的应用程序图标时启动的活动).
I have activities A and B. The A is the one with LAUNCHER intent-filter (i.e. the activity that is started when we click the app icon on home screen).
A 使用 startActivity(new Intent(A.this, B.class))
启动 B.
A launches B using startActivity(new Intent(A.this, B.class))
.
当用户打开 B 活动,然后将我的应用程序置于后台,然后我的应用程序进程被杀死,当用户再次启动我的应用程序时,打开 B 而不是 A.
When the user has the B activity open, and then put my application into the background, and later my application's process is killed, when the user starts my application again, B is opened instead of A.
这导致我的应用强制关闭,因为 A 是初始化我的应用所需资源的 Activity,当 B 尝试访问未初始化的资源时,B 崩溃.
This caused a force close in my app, because A is the activity that initializes the resources my app needs, and when B tried to access the uninitialized resources, B crashes.
您有什么建议在这种情况下我应该怎么做?
Do you have any suggestions what should I do in this situation?
推荐答案
嗯,你真的应该让活动 B 也初始化你的资源.但是你可以把 android:clearTaskOnLaunch="true"
在您的清单中为活动 A 让启动器始终转到该活动.
Well you should really have activity B initialize your resources too. But you can put android:clearTaskOnLaunch="true"
in your manifest for activity A to have the launcher always go to that activity.
这篇关于Android:如何使启动器始终打开主活动而不是子活动?(或其他)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Android:如何使启动器始终打开主活动而不是子活动?(或其他)
基础教程推荐
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01