0

Wake Lock works fine in the first activity but when the user press the button for change activity the app crash...Why? I used wl.release(); Also i used permission WakeLock in the manifest.Also i had registered the activity 2 in the manifest.

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();
 }
user2342687
  • 227
  • 1
  • 6
  • 17

0 Answers0