Skip to content

Instantly share code, notes, and snippets.

@yerenutku
Created December 11, 2016 17:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yerenutku/63baf7f0c8231d75c70a9b550f24052b to your computer and use it in GitHub Desktop.
Save yerenutku/63baf7f0c8231d75c70a9b550f24052b to your computer and use it in GitHub Desktop.
public class UpdatingWidget extends AppWidgetProvider {
private PendingIntent service;
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
final AlarmManager manager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
final Intent i = new Intent(context, UpdateService.class);
if (service == null) {
service = PendingIntent.getService(context, 0, i, PendingIntent.FLAG_CANCEL_CURRENT);
}
manager.setRepeating(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime(), 60000, service);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment