Hello Techies , I am facing a problem in achieving some task for my personal application. I want to make a service to run continuously once it is started and should not stop even if the screen gets locked or phone goes to sleep mode! I made the service to return as sticky but even then the service runs until my screen is not locked or it doesn't go to sleep mode! Thanks in advance for the help! :)
Asked
Active
Viewed 2,799 times
1
-
Can you post some code regarding your service? Like do you start it via startService or do you connect directly with the binder? – Greg Giacovelli Jan 30 '14 at 07:32
-
Service runs even if your starting component is destroyed unless the service is a Bind service. – Faizan Mubasher Jan 30 '14 at 07:33
-
@GregGiacovelli Thanks for the reply. I am starting the service on creation of my activity and I am doing it using startService not through iBinder – Nitin Mesta Jan 30 '14 at 10:15
-
@FaizanMubasher thanks for replying! I am not using iBinder but still my service stops when phone gets locked! – Nitin Mesta Jan 30 '14 at 10:16
2 Answers
4
I think you can try timer task it will help you
TimerTask scanTask;
final Handler handler = new Handler();
Timer t = new Timer();
public void doWifiScan(){
scanTask = new TimerTask() {
public void run() {
handler.post(new Runnable() {
public void run() {
wifiManager.scan(context);
Log.d("TIMER", "Timer set off");
}
});
}};
t.schedule(scanTask, 300, 30000);
}

skyshine
- 2,767
- 7
- 44
- 84
-
Thank you very much peter! I will try this one and let you know if it works! – Nitin Mesta Jan 30 '14 at 10:18