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
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.
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.
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.
Related
i am currently trying to get code running as a background service.
what this code does is:
send request to server with current location of the user
receive response
parse response
save into model (singleton)
and this is set to happen in a 30 sec interval again and again.
now if my app stays in the background for too long, it will get disposed by the device and that code will not be executed anymore. what would be the right kind of background service for this usecase?
one of my main concernes is that i save my data in a singleton. but if my app is disposed this singleton will probably not exist anymore.
intent service doesnt make sense imho because it runs a one time tasks and has to be restarted from an app that might already be disposed at that point.
using the alarm manager would mean that i will have to save everything out of the app (sqllite for example) and then retrieve that data when the activity is started again which sounds rather complicated.
can someone please help me out here?
thanks in advance!
You sir needs the service of GCM
https://developers.google.com/cloud-messaging/
Thats exactly what you need for your desire ;)
But it's not less complicated as sticking to background services.
Also you can do a Hack: having two services watching your service to keep on running and itself...I swear when the User doesn't stop your app manually in the menu the System won't be able to stop them itself. Foolproof.
I am posting images using JSON. Whenever I take a picture i have to call the webservice.
This webservice call may take some time. I dont want to use Thread nor Asynchronous Task for this.
I want to call the Webservice in background and able to perform operations in foreground(button click, entering some data in edittext etc).
I guess this can be achieved by using Service. Please provide me some tutorials for this.
Is there any way?
Thanks in advance.
Services are basically used when we want to run some code in background even when a application or the present activity gets closed. Use Services only if you need it and be sure to destroy it when you are done otherwise you will waste memory and that is not good.
Here are some great tutorials of implementing service. Firstly make some sample codes to learn how to handle services and see their lifecycle, etc. and then try to implement them in you code otherwise you may be confused xamarin.com vogella.com and technotopia.com. Happy Coding!!!
If you need to handle upload within a serial queue service, take a look at IntentService.
and implement the abstracted onHandleIntent() method.
I am doing an application on Android that gets locations from a webservice and puts it on a map. The app should do it every 15 seconds. What is the best way to do this?The communicaton with the webservice is made using REST architecture and the webservice returns a JSON. Should i use a Service or AsyncTask? thanks
You'll for sure see different opinions around here regarding this topic, but I've been using ExecutorServices for a while and they work really nice. Don't forget to stop it whenever the activity pauses.
Remainder: if the application should be an always running thing (for example a GPS navigation, or some type of location based social gaming) then you might want to use a Service that will also use an ExecutorService and don't forget to put a Notification letting users know that it's still running and that they can cancel if they wish to.
is there any way to listen a Server action using a service?i want to check server message for life time and do actions based on server message,please post a sample code
I think what you looking for is a long time running background service, check out this SO question.
Here i have example of using service, but it's doing some other thing. You can work it out..
http://maephv.blogspot.com/2011/08/android-notification-in-your.html
But remember, that when screen comes off, services freeze. I don't know yet how to fix it, but maybe "background process" is word to google
In my app i need to parse the XML file & display info on activity. just like stock market as & when information at server got updated i need to parse the xml & display the info.I need to hit the server after 5 minutes & display the updated info on activity. I have tried using AsyncTask & timer but something going wrong.If any one is having demo then please provide link,tutorial..
It's extermely urgent..
thnx for any help....
Sounds like you want to run a polling loop in the background? You should be able to use a timer to kick off the check and an async task to actually request/parse. There's a bit of complexity in setting up the timer handling, the accepted answer to this question should help however:
How to get XML using AsyncTask and Timer?