Created
January 14, 2019 21:46
-
-
Save azzumw/51834fc454c73ecdb505cd7f6269fcc5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.macintosh.thebakingappproject; | |
import android.app.IntentService; | |
import android.app.Service; | |
import android.appwidget.AppWidgetManager; | |
import android.content.ComponentName; | |
import android.content.Context; | |
import android.content.Intent; | |
import android.os.Build; | |
import android.support.annotation.Nullable; | |
public class WidgetUpdateService extends IntentService { | |
public static final String ACTION_UPDATE_LIST_VIEW = "com.example.macintosh.thebakingappproject.widgetupdateservice.update_app_widget_list"; | |
public WidgetUpdateService() { | |
super("WidgetUpdateService"); | |
} | |
@Override | |
protected void onHandleIntent(@Nullable Intent intent) { | |
if (intent != null) { | |
final String action = intent.getAction(); | |
if(ACTION_UPDATE_LIST_VIEW.equals(action)){ | |
handleActionUpdateListView(); | |
} | |
} | |
} | |
private void handleActionUpdateListView(){ | |
//get the recipe data | |
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(this); | |
int[] appWidgetIds = appWidgetManager.getAppWidgetIds(new ComponentName(this, WidgetProvider.class)); | |
WidgetProvider.updateAllAppWidget(this, appWidgetManager,appWidgetIds); | |
appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetIds, R.id.widgetListView); | |
} | |
public static void startActionUpdateAppWidgets(Context context) { | |
Intent intent = new Intent(context, WidgetUpdateService.class); | |
intent.setAction(ACTION_UPDATE_LIST_VIEW); | |
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { | |
// context.startForegroundService(intent); | |
// } | |
// else { | |
// context.startService(intent); | |
// } | |
context.startService(intent); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment