3

The main activity is specified in AndroidManifest.xml with:

        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>

But I don't know how to dynamically specify the first activity according code logic.

yava
  • 2,511
  • 3
  • 20
  • 17

3 Answers3

9

Specify a default Activity which contains the logic to start whichever Activity you want within its onCreate method.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // CODE HERE TO CREATE INTENT
    startActivity(intent);
    finish();
}
Ian G. Clifton
  • 9,349
  • 2
  • 33
  • 34
3

@Ian G's answer is correct - but I think his can be improved by removing the launch activity from the backstack. This is what @gardarh is trying to say.

I have a full answer at this related question that basically shows both sides of the problem, activity code & manifest code:

The activity code is basically the same as @Ian's, so I won't repost that. But I will include my addition to his answer.


Manifest Declaration (note the noHistory="true" parameter):

    <activity
        android:name=".activity.EntryActivity"
        android:launchMode="singleInstance"
        android:noHistory="true" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

Community
  • 1
  • 1
Richard Le Mesurier
  • 29,432
  • 22
  • 140
  • 255
0

I don't have points to add comments but the removing the launcher activity from the back stack might be useful in some cases. This SO post explains how to do this: Removing an activity from the history stack

Community
  • 1
  • 1
gardarh
  • 3,084
  • 2
  • 28
  • 31