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?
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With