Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: How to make launcher always open the main activity instead of child activity? (or otherwise)

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 launches B using startActivity(new Intent(A.this, B.class)).

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.

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?

like image 332
Randy Sugianto 'Yuku' Avatar asked May 26 '10 03:05

Randy Sugianto 'Yuku'


People also ask

How do I change the default activity in Android?

In Android, you can configure the starting activity (default activity) of your application via following “intent-filter” in “AndroidManifest. xml“. See following code snippet to configure a activity class “logoActivity” as the default activity.

Can we have two launcher activities in android?

With multiple launcher activities, developers can achieve the presentation of multiple launcher interfaces with the installation of a single app. This could be used to separate an app's actionable functions on the Android OS launcher.

What is Android intent Action Main?

android. intent. action. MAIN means that this activity is the entry point of the application, i.e. when you launch the application, this activity is created.


1 Answers

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.

like image 119
Jason Hanley Avatar answered Oct 02 '22 17:10

Jason Hanley