user2275410
user2275410

Reputation: 80

Android main activity does not launch on start

The main activity does not launch when I open the application; I close it by clicking on the home button. When the app starts, it opens on the same page where I was when I clicked the home button. It somehow remembers the last page I was at, and opens that page instead of the launcher activity. I added onDestroy() to onPause() on all the activities, but that didn't help either.

I am not sure what code to add here, so I'm attaching my AndroidManifest. Thanks! Below are the three activities in the AndroidManifest.

  <activity android:name="example.Activity1" android:label="MyApp" 
        android:configChanges="orientation" android:screenOrientation="portrait">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>



    <activity
        android:name="example.Activity2"
        android:configChanges="orientation"
        android:screenOrientation="portrait" >
    </activity>
    <activity
        android:name="example.Activity3"
        android:configChanges="orientation"
        android:screenOrientation="portrait" >
    </activity>

Upvotes: 3

Views: 3935

Answers (3)

alvaropgl
alvaropgl

Reputation: 850

Your activity is saved on the backstack. Play with the flags passed to the intent when you create your activity. For example, FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET will clear all the activities from this to up the backstack.

Intent myIntent = new Intent(this, MyActivity.class);
myIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
startActivity(myintent);

When you close, o exit myintent Activity, when you reopen you app it will clear delete myintent Activity from the backstack and all the activities opened from this activity.

Upvotes: 0

Virag Brahme
Virag Brahme

Reputation: 2062

When Home button is pressed, onStop method is called in your activity. So what you may do is to add finish(); in onStop method to destroy your activity.

Upvotes: 4

Anirudh
Anirudh

Reputation: 2090

Make sure you activity name includes you entire package name instead of example.

Or just replace android:name="example.Activity1" with android:name=".Activity1"

Upvotes: 0

Related Questions