简体   繁体   中英

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>

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.

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

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM