【发布时间】:2020-06-18 11:14:54
【问题描述】:
各位,上周我尝试了一些 android 开发,但目前遇到以下错误:我正在后台运行一个带有服务的计时器。时间到了,即使手机处于锁定状态,也应打开活动。使用以下代码,虽然没有锁定一切都很好。但是从锁定屏幕打开时,它总是会打开两次.. :/
我在 onCreate 中添加了这个,让它从锁定屏幕打开。
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//allow window to be popped up while in lock screen
Window window = this.getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
window.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
window.addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
setContentView(R.layout.activity_entry);
我正在通过意图从服务中打开活动。
callEntryActivityIntent = new Intent(this, EntryActivity.class);
callEntryActivityIntent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
pendingIntent = PendingIntent.getActivity(this, 0, callEntryActivityIntent, 0);
当计时器结束时 -> startActivity(callEntryActivityIntent);
也许有人有想法。我真的是 android 开发的新手,两周前就开始了。
【问题讨论】:
标签: java android android-intent android-service lockscreen