Lockscreen is displayed between activities
Asked Answered
P

1

13

I work on a kiosk app which can launch other android apps. It runs on top of the lockscreen. The issue I am seeing is that the lockscreen is displayed briefly between activities. We must keep the tablet locked so unlocking is not an option.

I have been able reproduce this with a super simple case. Both activities are nearly identical. The application is a device administrator and can be displayed above the keyguard. I have also tried not using finish() at all but that didn't fix the issue.

public class MainActivity extends Activity {

    private Handler h = new Handler();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Button bneg1 = (Button) findViewById(R.id.bneg1);
        bneg1.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                h.post(new Runnable() {
                    @Override
                    public void run() {
                        Intent i = new Intent(MainActivity.this, SecondActivity.class);
                        startActivity(i);
                        finish();
                    }
                });
            }
        });
    }
}

How can I launch the other activity without it briefly showing the lockscreen first?

Prae answered 13/3, 2014 at 20:7 Comment(2)
Have you tried FLAG_ACTIVITY_NO_ANIMATION, with overridePendingTransition(0, 0) after startActivity(). This keeps new activities from "sliding-in" and instead just starts them up immediately. not sure it is the fix, but worth a look.Beauchamp
I have tried that. It didn't appear to make any difference.Prae
A
4

How can I launch the other activity without it briefly showing the lockscreen first?

An easier way of achieving this would be to have a dummy (plain-view) activity running before you launch activity-1. This way, when you do finish activity-1, dummy-activity will take over, followed by activity-2 coming into the foreground.

You will (most likely) also need to tell the system not to provide window animations. Do so by adding this to your application theme:

<item name="android:windowAnimationStyle">@null</item>
Avaricious answered 16/3, 2014 at 6:43 Comment(7)
This just might work. I'll post back on my findings.Prae
So I haven't truly tested this, however: Based on previous testing this won't work. I completely removed finish() from both activities. This would have caused the same effect as having a dummy activity since I would still have activities in the stack. The lockscreen still would show briefly.Prae
@Prae I suggested this approach without trying it first-hand. Apologies. It doesn't work. What else I tried: Showing a screen-sized PopupWindow with TYPE_TOAST before launching activity-2 (dismissing it right after)- doesn't work. Adding a screen-sized opaque view using window manager's addView(...) with TYPE_SYSTEM_ALERT set - doesn't work.Avaricious
@Prae What did work was using Fragments in place of Activities. Since you never leave an activity while using fragments, the lock-screen does not interfere - not even briefly. I understand that going from activities to fragments isn't a straight-forward decision (for any scale application). But, you can consider doing so as a last resort - in case nothing else turns up.Avaricious
Thanks @Vikram. Unfortunately it is a kiosk application which launches 3rd party apps which we have no control over. I was hoping for a way to get to the 3rd party app without displaying the lock screen. Then it would be up to the 3rd party app to move in and out of activities without showing the lockscreen. But even if I develop the 3rd party app I have no way to move in and out of activities without showing the lockscreen.Prae
@Prae Just wondering, does the lock-screen show when you don't set a secure lock (like a pattern lock etc.)? If it doesn't, you can probably set a non-secure unlock mechanism like slide-lock and declare your application as a home screen app: using category.HOME and category.DEFAULT as intent-filters. This way, you will restrict the user from accessing android's default launcher - which I am guessing is the purpose of a secure lock.Avaricious
I haven't tried that. Note: We already are the home app. That was my first thought (Letting my home app show on top). I'll try the insecure idea.Prae

© 2022 - 2024 — McMap. All rights reserved.