Pavlo28
Pavlo28

Reputation: 1606

Android 14 predictive back gesture - blinking white background color

According to the docs, we simply should update 'androidx.activity:activity' version in the build.gradle and add android:enableOnBackInvokedCallback="true" to the Manifest to make predictive back work. I made both changes, the animation works in general, but the screen is blinking white while transitioning from my Activity Two to Activity One. I believe it's something like a global background of the app, however, android:windowBackground is dark in both activities. Both activities are ComponentActivity and the UI is Jetpack Compose based (there are no Composables with white background). What have I missed?

enter image description here

Update: I created a new project with two activities:

class Activity1 : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            Box(modifier = Modifier.fillMaxSize().background(Color.Black)) {
                Button(onClick = {
                    startActivity(Intent(this@Activity1, Activity2::class.java))
                }) {
                    Text(text = "TO ACTIVITY 2", color = Color.White)
                }
            }
        }
    }
}

class Activity2: ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            Box(modifier = Modifier.fillMaxSize().background(Color.Black)) {

            }
        }
    }
}

the theme for both activities is:

<style name="Theme.PredBackTest" parent="android:Theme.Material.Light.NoActionBar">
    <item name="android:windowBackground">@android:color/black</item>
</style>

however, the result is same - it's blinking white while moving back from Activity2 to Activity1.

Upvotes: 2

Views: 1231

Answers (2)

Matej Drobnič
Matej Drobnič

Reputation: 1191

What we did to workaround for this is disable predictive back on every activity except our main activity (only one that actually exits out of the app): https://developer.android.com/guide/navigation/custom-back/predictive-back-gesture#opt-activity-level

<manifest ...>
<application . . .

    android:enableOnBackInvokedCallback="false">

    <activity
        android:name=".MainActivity"
        android:enableOnBackInvokedCallback="true"
        ...
    </activity>
    <activity
        android:name=".SecondActivity"
        android:enableOnBackInvokedCallback="false"
        ...
    </activity>
</application>

Ideal fix for this would be transitioning to single activity, but until this is done, above workaround would do.

Not sure why Google decided on this blinking animation for Android 14, it looks terrible for on our apps.

Upvotes: 0

ΓDΛ
ΓDΛ

Reputation: 11110

You need to update your theme android:Theme.Material.DayNight

Upvotes: 1

Related Questions