Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lockscreen is displayed between activities

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?

like image 465
Randy Avatar asked Mar 13 '14 20:03

Randy


People also ask

How do I show my activity on my lock screen?

To enable it you have to go to the app configuration -> Other permissions -> Show On Lock screen.

What is the purpose of a lockscreen?

In general, a lock screen is an interface on a computer, smartphone, or tablet that appears upon startup. Access to all of the device's applications are limited when it is locked, preventing unwanted users from accessing the device's contents and settings.


1 Answers

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>
like image 136
Vikram Avatar answered Oct 11 '22 19:10

Vikram