如果应用已经在内存中,如何使加载屏幕不加载

blu*_*yte 0 android splash-screen android-activity

我有一些spash屏幕的麻烦.当我启动应用程序时,启动屏幕活动会启动几秒钟.主要活动启动后.

如果我按下主活动上的主页按钮然后从应用程序列表重新启动应用程序,则尽管应用程序已经在后台,但启动活动仍会再次启动.但我希望主要活动从记忆中恢复.

如果我按下后退按钮,那么android会将我返回到主活动的上一个副本.

制作启动画面只需要出现一次我需要做什么?如何在点击主页按钮之前从我看到的最后一个屏幕重新启动我的应用程序?

    <activity
            android:name=".ui.SplashActivity"
            android:noHistory="true"
            android:screenOrientation="portrait"
            android:label="@string/app_name">

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

    <activity android:name=".ui.MainActivity"/>
Run Code Online (Sandbox Code Playgroud)

Phi*_*hil 5

这是一个设计问题.您的启动器活动不应该是您的启动画面活动.相反,在主活动的onCreate方法中打开您的启动活动.这样,如果它是新打开的,则调用onCreate并显示启动画面.否则,如果仅恢复应用程序,调用onResume,则不会调用打开启动屏幕活动.

然后你可以将你的清单改为:

<activity
        android:name=".ui.MainActivity"
        android:noHistory="true"
        android:screenOrientation="portrait"
        android:label="@string/app_name">

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

<activity android:name=".ui.SplashActivity"/>
Run Code Online (Sandbox Code Playgroud)