简体   繁体   中英

first activity's onPause not called when start two activity continuously and the second activity with translucent theme

Just as the title described, when I start two activity continuously, and the second activity has a theme that windowIsTranslucent is true。 I found that the first activity's onPause was not called, it means that all of this activities were under resumed status.
this problem just happen on android pie(API 28) or higher

startActivity(new Intent(this, Activity1.class));
startActivity(new Intent(this, Activity2.class));
<resources>

    <!-- Base application theme. -->
    <style name="AppThemeA" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="android:windowIsTranslucent">true</item>
    </style>

</resources>
    <application
        android:name="com.taou.maimai.MyApplication"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppThemeA">
        <activity android:name=".MainActivity"
            android:launchMode="singleTask"
            >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name="com.taou.maimai.Activity1" />
        <activity android:name="com.taou.maimai.Activity2"
            />
    </application>

Try to set the theme in onCreate like this:

 public void onCreate(..){
    super.onCreate();
    setTheme(R.style.transcluent_theme);
    setContentView(R.layout.main_activity_2);

  }

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