title: Android - AppWidgets, AlarmManager and AsyncTask
body: <p>I'm not having much luck with updating an app widget with <code>AlarmManager</code> generated broadcasts. Here's what I do:</p>
  
  <p>Initializing <code>AlarmManager</code> on <code>AppWidgetProvider#onEnabled</code></p>
  
  <pre><code>AlarmManager alarms = (AlarmManager) context.getSystemService(
          Context.ALARM_SERVICE);
      alarms.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, 
      SystemClock.elapsedRealtime(), 60000, pendingIntent);
  </code></pre>
  
  <p>I also define broadcast receiver that simply listens for the updates that fired by the <code>AlarmManager</code>. When update is fired code runs <code>AsyncTask</code> that makes a network call. When the <code>AsyncTask</code> is completed (<code>onPostExecute</code>) it uses previously obtained instance of <code>AppWidgetManager</code> to update the widget(s).
  It all actually runs well until in the logs I see message <code>"Process com.foo.myapp (pid 12345) has died"</code> after which the <code>AlarmManager</code> never fires another update.</p>
  
  <p>Do I need to have some sort of check which will restart the alarms? For example when user access the parent app of the widget? How do I ensure that I can complete the long running task and come back to the widget if my app dies in the middle of the request?</p>