How to resume the service where it was stopped.

Put your problem here if it does not fit any of the other categories.

How to resume the service where it was stopped.

Postby ranjandeo » Tue Apr 05, 2011 7:25 am

Hi All,

I am having a problem with service and timer.
I have created a service that is supposed to do some job in background after each specified interval.
I works perfect while device is on, but when device is restarted then I want to run the service according to the specified interval only, means it should keep track how much time was passed when device was shutdown so when device is powered on it should wait for remaining time and then do the specified job.

But what it does now, it just started the service from beginning as device is restarted.
If any one is having some idea how it can be done then please help me.
Ranjan Deo
User avatar
ranjandeo
Experienced Developer
Experienced Developer
 
Posts: 84
Joined: Mon May 31, 2010 6:20 am
Location: Kolkata, India

Top

Re: How to resume the service where it was stopped.

Postby strider2023 » Tue Apr 05, 2011 7:51 am

Hi Ranjan,

Android services can save data at different states of you application. You can pass custom data in onResume() and onPause() for your service. Refer to android's documentation for more details.
strider2023
Senior Developer
Senior Developer
 
Posts: 126
Joined: Tue Mar 02, 2010 6:34 am
Location: Chennai, India

Re: How to resume the service where it was stopped.

Postby ranjandeo » Tue Apr 05, 2011 3:15 pm

Thanks a lot for your response :-)

I fixed the problem.
What I did is, Now i store the timer value whenever my task is executed.
As my application was working perfect if device is not restarted, so I just took some flag and set it when device's BOOT is completed and then I check accordingly and calculate the remaining time for the task or if time is already passed then I calculate the next schedule.

So now application works as it was expected :-)
Ranjan Deo
User avatar
ranjandeo
Experienced Developer
Experienced Developer
 
Posts: 84
Joined: Mon May 31, 2010 6:20 am
Location: Kolkata, India

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 17 guests