W1 is not defined in onDestroy.
Try this:
public class WakeLockService extends Service {
PowerManager.WakeLock wl; // NOTE CHANGE HERE
@Override
public IBinder onBind(Intent arg0) {
// TODO Auto-generated method stub
return null;
}
public void onCreate() {
PowerManager pm = (PowerManager) getSystemService
(Context.POWER_SERVICE);
wl = pm.newWakeLock (PowerManager.FULL_WAKE_LOCK, "My Tag");
//NOTE CHANGE HERE
wl.acquire();
}
public void onDestroy() {
wl.release();
}
Sincerely,
Brad Gies
-----------------------------------------------------------------
Brad Gies
27415 Greenfield Rd, # 2,
Southfield, MI, USA
48076
www.bgies.com www.truckerphone.com
www.EDI-Easy.com www.EDI-Simple.com
-----------------------------------------------------------------
Moderation in everything, including abstinence
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Thomas Riley
Sent: Saturday, June 13, 2009 6:05 PM
To: Android Developers
Subject: [android-developers] Wake Locks and Services
I need to use a wakelock to hold the screen active while its required.
I was recommended to use a service which I have been trying but on the
onDestroy I am getting "wl cannot be resolved". Code below:
public class WakeLockService extends Service {
@Override
public IBinder onBind(Intent arg0) {
// TODO Auto-generated method stub
return null;
}
public void onCreate() {
PowerManager pm = (PowerManager) getSystemService
(Context.POWER_SERVICE);
PowerManager.WakeLock wl = pm.newWakeLock
(PowerManager.FULL_WAKE_LOCK, "My Tag");
wl.acquire();
}
public void onDestroy() {
wl.release();
}
}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---