Android:如何使启动器始终打开主活动而不是子活动?(或其他)

Android: How to make launcher always open the main activity instead of child activity? (or otherwise)(Android:如何使启动器始终打开主活动而不是子活动?(或其他))
本文介绍了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:如何使启动器始终打开主活动而不是子活动?(或其他)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

How to target newer versions in .gitlab-ci.yml using auto devops (java 11 instead of 8 and Android 31 instead of 29)(如何在.gitlab-ci.yml中使用自动开发工具(Java 11而不是8,Android 31而不是29)瞄准较新的版本)
Android + coreLibraryDesugaring: which Java 11 APIs can I expect to work?(Android+core LibraryDesugering:我可以期待哪些Java 11API能够工作?)
How to render something in an if statement React Native(如何在If语句中呈现某些内容Reaction Native)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)
Using Firebase Firestore in offline only mode(在仅脱机模式下使用Firebase FiRestore)
Crash on Google Play Pre-Launch Report: java.lang.NoSuchMethodError(Google Play发布前崩溃报告:java.lang.NoSuchMethodError)