Wake Lock在第一个活动中工作正常,但当用户按下更改活动按钮时,应用程序崩溃...为什么?我用过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();
}