Hello all, i've been noticing this problem for a very long time, i have read all the threads that talk about Services, I stopped working on an app almost a year ago because i could not figure out why my Services were being killed and not re-started.
Basically i was working on an Email Client App, I use Starter Service as the entry point to initialize, connected and authenticate the user's email address and login information, I use a library i wrapped that takes care of the oAuth2 part of it, I can authenticate the email address and login using the Access Token from the oAuth2 side of it, all this works just fine, i can retrieve all the emails from the Inbox and display them on a listview just fine.
The problem is that I have a separate Service which checks for New Emails every 30 seconds and displays a notification if there's a new email, Everything works fine as long as i keep my USB cable connected to the phone, i have even created a file which logs all the important events to it just so that I can see what's going on when I disconnect the USB cable. I do acquire a Partial lock at the beginning of the Service to prevent the CPU from going to sleep as advised on a few threads i've read.
The application runs fine for a while after disconnecting the USB cable, the issue is that the based on the logs i've obtained from the logs file i can see that the Service will stop being re-scheduled after a while, i can even see the Starter Service is also stopped and not re-started, I would like to get to the bottom of this problem if it is a problem at all, i wouldn't doubt that I might be doing something wrong, but i have tried extensively to make this app work but got frustrated and stopped working on it as I mentioned before.
I use StarServiceAt to schedule the service to be started every 30 seconds, I can see in the logs file that indeed the service is re-started every 30 seconds for a while but then it just stops, I have also added Try, Catch blocks everywhere in my code and log the exceptions to the logs file but so far I have not seen any errors/exceptions in the logs file that tells me something crashed, at least that would give me an idea of what is going on, but the Services just stop.
Based on the last logs file i obtained from a test done last night the app/Services only ran for about 43 minutes, I re-started the app this morning at 7:21AM and the Services stopped at 7:47AM, i am attaching the logs file from this morning's run.
One thing i did noticed is that while checking in the logs if the Services is started every 30 seconds, at 7:34 the service was re-started and re-scheduled but it didn't get re-started until 7:37 that's about 3 minutes difference, why is that?
any how, i hope someone who has came across this issue can shed some light, maybe i just don't understand how to use Services?.
I have replaced part of the access token in the logs file with 'XXXX" for security purposes.
Thanks everyone.
Basically i was working on an Email Client App, I use Starter Service as the entry point to initialize, connected and authenticate the user's email address and login information, I use a library i wrapped that takes care of the oAuth2 part of it, I can authenticate the email address and login using the Access Token from the oAuth2 side of it, all this works just fine, i can retrieve all the emails from the Inbox and display them on a listview just fine.
The problem is that I have a separate Service which checks for New Emails every 30 seconds and displays a notification if there's a new email, Everything works fine as long as i keep my USB cable connected to the phone, i have even created a file which logs all the important events to it just so that I can see what's going on when I disconnect the USB cable. I do acquire a Partial lock at the beginning of the Service to prevent the CPU from going to sleep as advised on a few threads i've read.
The application runs fine for a while after disconnecting the USB cable, the issue is that the based on the logs i've obtained from the logs file i can see that the Service will stop being re-scheduled after a while, i can even see the Starter Service is also stopped and not re-started, I would like to get to the bottom of this problem if it is a problem at all, i wouldn't doubt that I might be doing something wrong, but i have tried extensively to make this app work but got frustrated and stopped working on it as I mentioned before.
I use StarServiceAt to schedule the service to be started every 30 seconds, I can see in the logs file that indeed the service is re-started every 30 seconds for a while but then it just stops, I have also added Try, Catch blocks everywhere in my code and log the exceptions to the logs file but so far I have not seen any errors/exceptions in the logs file that tells me something crashed, at least that would give me an idea of what is going on, but the Services just stop.
Based on the last logs file i obtained from a test done last night the app/Services only ran for about 43 minutes, I re-started the app this morning at 7:21AM and the Services stopped at 7:47AM, i am attaching the logs file from this morning's run.
One thing i did noticed is that while checking in the logs if the Services is started every 30 seconds, at 7:34 the service was re-started and re-scheduled but it didn't get re-started until 7:37 that's about 3 minutes difference, why is that?
any how, i hope someone who has came across this issue can shed some light, maybe i just don't understand how to use Services?.
I have replaced part of the access token in the logs file with 'XXXX" for security purposes.
Thanks everyone.