With security keyguard active transition between a

2019-05-14 09:07发布

问题:

I have my main activity A and when the user presses a button i open another activity B. But when this happens B doesn't just appear on top of A:

  • A disappears
  • secure keyguard shows up
  • B appears

And when i get rid of B the same thing happens. This is annoying because there's a lot of flickering with no real purpose on the screen. Is there any way to achieve direct transition from A to B while keyguard is active without merging the 2 activities into 1?

Here is what i'm doing in onCreate for both activities:

getWindow().addFlags(
        WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
                | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
                | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);

And here is how i start the activity:

        final Intent intent = new Intent(Sand.this, EditRule.class);
        intent.putExtra(DB.KEY_PARENT_ID, id);
        intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
        startActivityForResult(intent, 0);
        overridePendingTransition(0, 0);

I also tried setting a null android:windowAnimationStyle in the activity theme but no luck.

UPDATE: i submitted this bug: https://code.google.com/p/android/issues/detail?id=68465&thanks=68465&ts=1397301860

Thanks, Teo

回答1:

I looked into this extensively (with a couple other engineers) a year or so ago on ICS and JB. It was not possible to avoid the flicker, which I strongly suspect is still the case in KitKat. You should file that bug.

(If you look at the Keyguard-related source in Android, it's a rather.. hefty mass of code/policy riddled with special cases. Since this case isn't explicitly documented anywhere, even if you can get it to work on one version, I would not rely on it working consistently.)

Ultimately, we worked around the issue by combining all of our must-not-flicker lockscreen UI into a single Activity. It was unpleasant, but it worked.