Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There is a wealth of resources on Services if you do a simple google search so I'm not going to explain how services work. The code snippet below uses a service that isn't bound to the Activity. </p> <p>My approach uses a Timer and a Task, note I use a task that repeats but this is not necessary. There are other ways you can approach this.</p> <pre><code>public class MyService extends Service { private Task retryTask; Timer myTimer; private boolean timerRunning = false; private long RETRY_TIME = 200000; private long START_TIME = 5000; @Override public IBinder onBind(Intent intent) { // TODO Auto-generated method stub return null; } @Override public void onCreate() { // TODO Auto-generated method stub super.onCreate(); myTimer = new Timer(); myTimer.scheduleAtFixedRate(new Task(), START_TIME, RETRY_TIME); timerRunning = true; } @Override public int onStartCommand(Intent intent, int flags, int startId) { if (!timerRunning) { myTimer = new Timer(); myTimer.scheduleAtFixedRate(new Task(), START_TIME, RETRY_TIME); timerRunning = true; } return super.onStartCommand(intent, flags, startId); } public class Task extends TimerTask { @Override public void run() { // DO WHAT YOU NEED TO DO HERE } } @Override public void onDestroy() { // TODO Auto-generated method stub super.onDestroy(); if (myTimer != null) { myTimer.cancel(); } timerRunning = false; } } </code></pre> <p>You would then start the service from an Activity using an Intent</p> <pre><code>Intent intent = new Intent(WorkSelectionActivity.this,MyService.class); startService(intent); </code></pre> <p>Hope this helps</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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