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?

Randy
  • 4,351
  • 2
  • 25
  • 46
  • 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. – zgc7009 Mar 13 '14 at 20:20
  • 1
    I have tried that. It didn't appear to make any difference. – Randy Mar 13 '14 at 20:26

1 Answers1

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>
Vikram
  • 51,313
  • 11
  • 93
  • 122
  • This just might work. I'll post back on my findings. – Randy Mar 16 '14 at 20:18
  • 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. – Randy Mar 17 '14 at 19:54
  • @Randy 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. – Vikram Mar 17 '14 at 21:35
  • 2
    @Randy 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. – Vikram Mar 17 '14 at 21:41
  • 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. – Randy Mar 17 '14 at 22:38
  • 1
    @Randy 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. – Vikram Mar 19 '14 at 19:52
  • 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. – Randy Mar 19 '14 at 20:14