I need to force the android device to stay alive while the application is running. There any way to do this ? I read here : Is there a way to force an android device to stay awake? about this, I tried to do this but probably I don't know to use correctly a Service.
This is the code I use :
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();
}
and in the first Activity of my Application, I put this :
Intent s = new Intent(this, WakeLockService.class);
startService(s);
Is it correct what I'm doing? Anyone can help me to do this ? Thanks in advance.