windowIsTranslucent changes lifecycle, but error o

2019-04-14 05:00发布

问题:

I'm experiencing that <item name="android:windowIsTranslucent">true</item> is changing the way Android Lifecycle is handled. I guess it's doing that because if the window is translucent, you can still see the underlaying activity. Let's call it activity A.

Let's go through the following example where we have another activity on top of activity A. This other activity is called B.

Activity A Started - This activity is the first activity
Activity A Stopped - Now you start activity B.
Activity B Started - This activity has windowIsTranslucent set to false. Hence we can't see anything of activity A anymore which is why activity A stopped.
Now hit the power button to go into lockscreen mode. 
Activity B Stopped - Since none is visible anymore activity B also stops. 

Let's look on another scenario where windowIsTranslucent is set to true for activity B.

Activity A Started - This activity is the first activity
Activity A Paused - Now you start activity B.
Activity B Started - This activity has windowIsTranslucent true (we want to see through it so it's still possible to see activity A)
Now hit the power button to go into lockscreen mode. 
Activity B Paused
Activity B Stopped
Activity A Stopped
Everything looks fine expect a RuntimeException is thrown that for me makes no sense since it's not stopped before?

E/ActivityThread: Performing stop of activity that is already stopped: {testapp/ActivityA}
java.lang.RuntimeException: Performing stop of activity that is already stopped: {testapp/ActivityA}
    at android.app.ActivityThread.performStopActivityInner(ActivityThread.java:3996)
    at android.app.ActivityThread.handleStopActivity(ActivityThread.java:4084)
    at android.app.ActivityThread.-wrap24(Unknown Source:0)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1622)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:164)
    at android.app.ActivityThread.main(ActivityThread.java:6494)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)

Any of you have any ideas why this is thrown? Any fix - or can i make an activity transparent without using windowIsTranslucent?