Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can use <code>AlarmManager</code> in Android for performing tasks of this nature. Please remember to register the <code>Broadcast Receiver</code> in <code>AndroidManifest.xml</code> so that you can properly use the below mentioned code:</p> <p>For Actual Example the Below mentioned code snippet would broadcast and intent that is specific to my application. I'll grab the intent and start the background service which performs my app specific functions. like :</p> <pre><code>Intent intent = new Intent(this, ServiceStarter.class); PendingIntent sender = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_ONE_SHOT); long scheduledTime = System.currentTimeMillis() + AlarmManager.INTERVAL_FIFTEEN_MINUTES; AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); alarmManager.set(AlarmManager.RTC_WAKEUP, scheduledTime, sender); </code></pre> <p>And Inside my <code>ServiceStarter</code> i'll do something like this is:</p> <pre><code> public class ServiceStarter extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { Intent serviceIntent; serviceIntent = new Intent(context, ActualService.class); context.startService(serviceIntent); } } </code></pre> <p>For shutting down the task similar lines of the code for <code>AlarmManager</code> would do just in the the <code>ServiceStopper</code> we need to stop the service like:</p> <pre><code>public class ServiceStopper extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { Intent serviceIntent; serviceIntent = new Intent(context, ActualService.class); context.stopService(serviceIntent); } } </code></pre> <p>Please revert if you need something else too.</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. This table or related slice is empty.
    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