Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Help with first Android Activity

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!

like image 702
w.donahue Avatar asked Jan 20 '23 18:01

w.donahue


1 Answers

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.

like image 107
CommonsWare Avatar answered Jan 30 '23 00:01

CommonsWare