0

I have an android app that calls a simple .asmx web service hosted in an asp.net application to get data and display it. I'm using ksoap2, and it's working perfectly, in the main activity I'm calling the webService. but my problem is that I want to call that .asmx web service every 30 minutes and get the data to display. I've searched and found the timertask class but I'm not sure if it will fit with what I want to do. any suggestions? Many thanks

Yasmine GreenApple
  • 438
  • 1
  • 5
  • 15

3 Answers3

1

Have a look at the Scheduled Task service: http://developer.android.com/reference/java/util/concurrent/ScheduledExecutorService.html

It will let you set up a recurring event every x seconds, and will keep running that task until you tell it to stop.

I found it to be pretty easy to set up.

Keab42
  • 688
  • 13
  • 28
  • thank you for the answer,I have a question: if a use the Scheduled task service, will my app call the service even if it is not running? – Yasmine GreenApple Jul 16 '12 at 17:34
  • The way I've used it is that I start it in a service, and stop it when the service is stopped. As suggested by @waqas716 above. That way when the app is sent to the background the service continues running, until the Android memory management chooses to kill it and/or the app. Bear in mind that once an app is minmised a user might not expect it to continue to download data, so you might want to stop or pause the scheduled task when the app is sent to the background. Otherwise you could eat a users data usage without them realising. – Keab42 Jul 17 '12 at 08:19
  • thank you for the help, I know it's too much asking but can you give me a sample code for that? – Yasmine GreenApple Jul 17 '12 at 08:32
1

You should have a Service to do this for you, Create a service and in that service you can schedule a thread to call your webservice every 30 minute even if your application isn't running. Here is the good tutorial on how to use service to let you get started. And this is a useful link about How and When to use Service. Please consider accepting the answer by clicking on left green Tick icon.

Community
  • 1
  • 1
Waqas
  • 4,411
  • 6
  • 27
  • 31
0

Sorry for answering my own question, thank you for your help. I've found a solution, I followed this tutorial and it worked perfectly.

Hope this will help.

DaveShaw
  • 52,123
  • 16
  • 112
  • 141
Yasmine GreenApple
  • 438
  • 1
  • 5
  • 15