唤醒锁在第一个活动中工作正常,但是当用户按下按钮更改活动时,应用程序崩溃......为什么?我用 wl.release(); 此外,我在清单中使用了权限 WakeLock。此外,我已经在清单中注册了活动 2。
private PowerManager.WakeLock wl;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_1);
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
wl = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "Application1");
wl.acquire();
btnMy = (Button)findViewById(R.id.buttonmy);
btnMy.setOnClickListener(btnListener);
}
private OnClickListener btnListener = new OnClickListener() {
public void onClick(View v) {
wl.release();
startActivity(new Intent(v.getContext(), Activity2.class));
//Intent myIntent = new Intent(v.getContext(), Activity2.class);
// startActivityForResult(myIntent, 0);
}
};
protected void onPause() {
super.onPause();
wl.release();
}
protected void onStop() {
super.onStop();
wl.release();
finish();
}
protected void onDestroy() {
super.onDestroy();
wl.release();
finish();
}