使用wakelock在服务的Android 1.5 [英] Using a wakelock in a service Android 1.5
问题描述
您好,我试图用一个服务来控制wakelock这样我就可以永久地留在我的应用程序运行在屏幕上。我创建了wakelock并激活它的onCreate(),并在的onDestroy释放它(),但是我得到的错误WL无法得到解决。有人能解释我怎么能渡过这个?低于code:
公共类WakeLockService延伸服务{
@覆盖
公众的IBinder onBind(意向为arg0){
// TODO自动生成方法存根
返回null;
}
@覆盖
公共无效的onCreate(){
电源管理器PM =(电源管理器)getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock WL = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK,我的标签);
wl.acquire();
}
@覆盖
公共无效的onDestroy(){
wl.release();
}
}
你是不是缺少行
PowerManager.WakeLock WL = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK,我的标签);
在的onDestroy()?它是在的onCreate()的局部变量,但它不是在的onDestroy()在所有声明。
或者,更可能的,你可能要使它类WakeLockService,而不是一个局部变量的字段。
Hello I am trying to use a service to control a wakelock so I can permanently leave the screen on when my application is running. I create the wakelock and activate it in onCreate() and release it in onDestroy() however I get the error "wl cannot be resolved". Can someone explain how I can get over 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();
}
}
Aren't you missing the line
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, "My Tag");
in onDestroy()? It is a local variable in onCreate(), but it is not declared in onDestroy() at all.
Or, more probable, you may want to make it a field of class WakeLockService instead of a local variable.
这篇关于使用wakelock在服务的Android 1.5的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!