Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<blockquote> <p>You can check the following links <a href="http://developer.android.com/reference/android/app/Service.html" rel="nofollow">http://developer.android.com/reference/android/app/Service.html</a> <a href="http://developer.android.com/guide/components/services.html" rel="nofollow">http://developer.android.com/guide/components/services.html</a> <a href="http://www.vogella.com/articles/AndroidServices/article.html" rel="nofollow">http://www.vogella.com/articles/AndroidServices/article.html</a></p> </blockquote> <p>You can add a thread which will download code after every 5 seconds. Here is the code</p> <pre><code>import android.app.Service; import android.content.Intent; import android.os.IBinder; import android.util.Log; import android.widget.Toast; public class MyService extends Service { String tag="TestService"; @Override public void onCreate() { super.onCreate(); Toast.makeText(this, "Service created...", Toast.LENGTH_LONG).show(); Log.i(tag, "Service created..."); } @Override public void onStart(Intent intent, int startId) { super.onStart(intent, startId); Log.i(tag, "Service started..."); fetchData(); } public void fetchData() { new Thread(new Runnable() { @Override public void run() { while(true) { final String strRes = downloadXML("http://uri.com"); runOnUiThread(new Runnable() { @Override public void run() { //do whatever once download complete } }); try{ Thread.sleep(5000); }catch(Exception ee){} } } }).start(); } @Override public void onDestroy() { super.onDestroy(); Toast.makeText(this, "Service destroyed...", Toast.LENGTH_LONG).show(); } @Override public IBinder onBind(Intent intent) { return null; } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload