I am working in android. I want to draw a comment window. in which I have a list View which shows comment retrieved from a API.
I want to call that API after 30 second again and again so i can show recent comments in my list view.
This is the code which is used to call my API.
HttpClient hc = new DefaultHttpClient();
HttpGet get = new HttpGet("192.168.1.127/CC/comment");
HttpResponse rp = hc.execute(get);
if (rp.getStatusLine().getStatusCode() == HttpStatus.SC_OK)
{
//Then put values in some text boxes.
}
I want to call this above code again and again after 10 second. Please help me in writing code. Your may give a short example to solve this type of problem. I have very short time and dont have time to search on google so please help how can i call API and change UI periodically ?
You Should use Service with Broadcast receiver.
Service will do your Task in Background but will not provide any UI so you need to register with Broadcast receiver.
Check this Sample , this sample show how to repeat a task and update UI using Service and Broadcast receiver.
Also refer this tutorial for further reference.