Lockscreen is displayed between activities

末鹿安然 提交于 2019-12-05 14:03:02

问题


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?


回答1:


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>


来源:https://stackoverflow.com/questions/22389765/lockscreen-is-displayed-between-activities

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!