Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>EDIT:</strong> Based on your code, you can pass your variables <code>myIntent</code> &amp; <code>myIntent2</code> into your <code>IntentService</code> class - you can then use them to recreate exact replicas of the pending intents used with the <code>AlarmManager</code>. </p> <p>Please note that it looks like you set an Alarm for each intent that repeats once "NOW" and then at intervals after that. You then implicitly start the service again i.e. you start the service twice "NOW". That looks like a mistake - look at the docs for the <a href="http://developer.android.com/reference/android/app/AlarmManager.html#setRepeating%28int,%20long,%20long,%20android.app.PendingIntent%29" rel="nofollow">AlarmManager.setRepeating()</a> method.</p> <hr> <p>Original answer below...</p> <p>Put this into your <code>IntentService</code>:</p> <pre><code>@Override protected void onHandleIntent(Intent intent) { try { // STOP SERVICE // DO YOUR WORK HERE } finally { // START SERVICE } } </code></pre> <p>You already have the code to stop the service. You can take the "start service" code from your <code>BroadcastReceiver</code> and put it in the finally block.</p> <p>I would not recommend overriding <code>onDestroy()</code> in general on Android.</p> <p><strong>NOTE</strong>: I don't think this is the best way to design your app, but I'm answering your question. Personally, I would have a method in my main <code>Service</code> that is able to disable &amp; enable its functionality - and then call that method instead of starting &amp; stopping the service.</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.
 

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