Reputation: 797
hi i am trying to wake lock for a particular amount of time but i am not getting the result i am using power manager class but i am not getting any result. i am using this code to wake lock
PowerManager.WakeLock wl;
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "My Tag");
Button b=(Button)findViewById(R.id.button1);
b.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View arg0) {
wl.acquire();
wl.release();
}});
}
here i am trying to invoke lock when i click button but its not working. i need to lock when the particular time out using broad cast receiver please suggest me Thanks in advance
Upvotes: 0
Views: 639
Reputation: 361
you should:
so you should test it by:
Button b1=(Button)findViewById(R.id.button1);
b1.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View arg0) {
wl.acquire();
}});
Button b2=(Button)findViewById(R.id.button2);
b2.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View arg0) {
wl.release();
}});
what's more:
Upvotes: 1
Reputation: 2229
You acquire and them immediatly release the WL. You have only to acquire WL in OnClick event and to handle a task to release it. I suggest you to use also a mWakeLockAcquired boolean variable to check the WL state.
Upvotes: 0