更改活动时唤醒锁定错误

时间:2013-07-16 08:18:18

标签: android power-management wakelock

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();
 }

0 个答案:

没有答案