简体   繁体   中英

Android app always opens the first activity on resuming

I'm working on an application that currently has two activites, a log in activity and a "frontpage" activity after that.

Whenever I switch away from the application and resume it either by relaunching it or using the application switcher, it will always re-open the log in activity. Even if I switch to my app from within the frontpage activity, it opens the log in activity.

None of my other apps have ever done this, even though they obviously all have a filter for the launcher in AndroidManifest.xml. I am aware that it is supposed to do this when the activity is killed, but I cannot comprehend why it would do that.

This is my AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest
    xmlns:android="http://schemas.android.com/apk/res/android"
    package="nl.vertinode.facepunch"
    android:versionCode="1"
    android:versionName="1.0">

    <!-- Android 2.2 -->
    <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="8" />

    <!-- Internet access -->
    <uses-permission android:name="android.permission.INTERNET" />

    <application android:icon="@drawable/icon" android:label="@string/app_name" android:name=".FPApp">        
        <!-- Login form -->
        <activity android:name="nl.vertinode.facepunch.LoginActivity" android:launchMode="singleTask" android:theme="@android:style/Theme.Light.NoTitleBar" android:windowSoftInputMode="stateHidden">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <!-- Frontpage view -->
        <activity android:name="nl.vertinode.facepunch.FrontpageActivity" android:theme="@android:style/Theme.Light.NoTitleBar" android:windowSoftInputMode="stateHidden">
        </activity>
    </application>
</manifest>

What could I be doing wrong?

I'm going to guess this has to do with your android:launchMode being singleTask . Try singleTop instead and see if you have the same problem. Also it could have to do with some code you have in your onPause for the other activities. Does it go back to your Login activity after going to sleep/waking back up as well?

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