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?
Related
I am facing a small issue with the android studio net work connect sample code.
Basically the code does exactly what i need, Press a button, it will fetch raw html a predetermined http.
However i was wondering if it is possible to make a while loop such that i do not need to press on the fetch button every time i want to get the data.
Regards.
http://developer.android.com/samples/NetworkConnect/index.html
What do you want exactly ? Do you want to refresh the web page or to check network connection ?
It seems you looking for refreshing the web page some period time.
While loop doesn't make sense. I suggest you to use Thread Handler or Timer.
Refer this link
you may get some ideas.
I have used the Udacity Google Developing Android Apps tutorial and other sources to get my application to fetch an XML file in HTTP via an AsyncTask and display it via a ListAdapter.
Now I am trying to eliminate the refresh button and have it update when the app starts, and then at intervals afterwards.
As far as I can tell, even though the code at Udacity creates a Service, it doesn't eliminate the refresh button.
The code at http://www.vogella.com/tutorials/AndroidServices/article.html#exercise_bindlocalservice only refreshes when the list is clicked.
Does anyone have sample code where the list auto refreshes?
yourListAdapter.notifyDataSetChanged();
or you can use activity life cycle to update the activity through onResume() or onStart() if needed! but i guess you are looking for the first answer to refresh ur listAdapter
if your auto means the content will update whenever there are new contents. You should check those new content by yourself , the classical way is set a Timer to check it . After you got the new content , you can use them to update the view .
Update:
See this:http://www.vogella.com/tutorials/AndroidTaskScheduling/article.html
The reason for not using Timer is not because Timer does 'bad things' but Android does, All running task or data will be stopped and recycled by Android's GC at anytime , so the Timer will be terminated at anytime.
If you have a service or an activity in your application which should perform a repetitive task you cannot reply on a TimerTask or similar approaches and control it from your Android component. Activities and services can be terminated at any point in time by the Android system to free up resources.
So , you can rely on AlarmManager or JobScheduler in the tutorials I post above.
All my questions were answered by using the BasicSyncAdapter example from Google.
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.
I am implementing one application related to downloads.
Based upon my requirement I want to get start and ending time each downloads.
For example the user downloads a app from android market after installing my app, then i need to get starting and ending time related to that download.
If any one know the solution please help me.
Thanks in advance.
Don't put direct link for download. Just put a php file which gets the address of file and let the user download it. In that case you can easily get the time with php. For the finish time it is not in your access but the best way is to use javascript on page which sends report of download to you via AJAX
Assuming that you want to display the start download time and the end download time the solution that comes to my mind is of using a AsyncTask where the start time can be displayed within the onPreExecute(), perform the download of app operation in doInBackground() and when the download finishes the time can be displayed in the onPostExecute(). HTH.
Warm greetings.
I am quite new to android currently & had fallen under a fix. The concern is i am running the app which performs multipart upload to a remote uri using HttpPost, if the upload fails, the data is then saved to sqllite.
Now as soon as the application starts my app firstly queries the db & if there is any unsent data it first send it then proceed ahead.
What i am looking for is a feature via which i can run this task in background, i can not place this peice of code in onPause because i have few other intents which give a call to Camera, image viewer, gps etc... Any suggestions how can i manage this & how can i acheive this. Is there any samples/links available for implementation like this.?
PS:- I have the application with one single Activity defined in Manifest, other are the inbuilt Broadcasters like Camera Intent, Media Player etc. Just an additional info
Any help will be highly appreciated.
It sounds like you need a Service: http://marakana.com/forums/android/examples/60.html
Please check below link for executing the task in bg.
http://developer.android.com/reference/android/os/AsyncTask.html