Click here to Skip to main content
15,913,055 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Guys

I Want Any One Help Me Here

Can Any One Here Have Idea About Refreshing My Android Service Every 5 Sec

Thanks All ,Best Regards
Posted
Comments
Manoj K Bhoir 22-Oct-12 7:46am    
Please Provide More Information in your Question. What type Of Service you are asking For? Android Built-In Services or Anything Else????
ali4050 22-Oct-12 8:39am    
Class MyService extends Service
Sergey Alexandrovich Kryukov 22-Oct-12 15:25pm    
OK, now what's "refresh service"? And what's the problem?
--SA
Manoj K Bhoir 23-Oct-12 0:48am    
If Your Class Contains Any Method Or Function to Refresh the Service then Create a Thread and Call this Service in that Thread! If you are Asking anything else then please explain what exact you want.

1 solution

You will need to create a runnable that does your refreshing, then reschedules itself to run again in 5 seconds.

Java
private Runnable runnable = new Runnable() {
   @Override
   public void run() {
      //Do your refreshing
      refresh();
      //This basically reruns this runnable in 5 seconds
      handler.postDelayed(this, 5000);
   }
};


Whereever you want to start refreshing, do this
Java
private Handler handler = new Handler();
handler.postDelayed(runnable, 5000);


Hope this helps
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900