Android:如何使启动器始终打开主活动而不是子活动?(或其他) [英] Android: How to make launcher always open the main activity instead of child activity? (or otherwise)

查看:28
本文介绍了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:如何使启动器始终打开主活动而不是子活动?(或其他)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆