Using wakelock in Android 1.5

Hello, I'm trying to use the wakelock management service so that I can leave the screen forever when the application is running. I create wakelock and activate it in onCreate () and release it in onDestroy (), but I get the error "wl cannot be resolved". Can someone explain how I can overcome this? Code below:

public class WakeLockService extends Service {

    @Override
    public IBinder onBind(Intent arg0) {
        // TODO Auto-generated method stub
        return null;
    }  
    @Override
    public void onCreate() {
        PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
        PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, "My Tag");
        wl.acquire();
    }
    @Override
    public void onDestroy() {
        wl.release();
    }
}
+5
source share
2 answers

You are missing a line

    PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, "My Tag");

in onDestroy ()? This is a local variable in onCreate (), but it is not declared at all in onDestroy ().

Or, more likely, you can make this a WakeLockService class field instead of a local variable.

+5

, , , . destroy()? , , . , , destroy() , /.

, , onCreate(). onCreate() , , , , , .

, -, . . A BroadcastReceiver , onReceive() . , stopSelf(), , , .

, , , , , , . , , ?

, , - , . , . , , - , . , , , ( /), .

+9

All Articles