When my app first opens my first activity that is presented to the user can vary based on configuration options. I only know how to hard code the first activity that runs when the app is running by adding something like this in the Manifest
<activity android:label="@string/app_name" android:name=".MyFirstActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Where MyFirstActivity is the class name of the first activity class to be run. How can I dynamically select which activity to run first when the app is first launched rather than hard code it in the manifest?
Thanks!
Option #1: In onCreate()
of MyFirstActivity
, call startActivity()
for the right activity, then finish()
.
Option #2: Define several activities with the LAUNCHER
<intent-filter>
, all but one disabled. On first run (or as needed), enable the right activity and disable the others. Downside: may require a phone reboot to update the launcher, since not all home screen launchers will detect your change.
Option #3: Redesign your GUI such that this is not an issue.
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