How to update widget layout at startup?

I create three widgets for my application, when I drag three widgets to the main screen, I get the same widget layout, but when I update, the widget layout will change.

How can I update three widget layouts right after dragging and dropping to the main screen?

Here is my code:

public class FullWidgetProvider extends AppWidgetProvider { private int widgetID; private static SimpleDateFormat formatter = new SimpleDateFormat("dd MMM yyyy hh:mm:ss a"); static String strWidgetText = ""; @Override public void onDeleted(Context context, int[] appWidgetIds) { // TODO Auto-generated method stub //super.onDeleted(context, appWidgetIds); // Toast.makeText(context, "onDeleted()", Toast.LENGTH_LONG).show(); } @Override public void onDisabled(Context context) { // TODO Auto-generated method stub //super.onDisabled(context); //Toast.makeText(context, "onDisabled()", Toast.LENGTH_LONG).show(); } @Override public void onEnabled(Context context) { // TODO Auto-generated method stub super.onEnabled(context); } @Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { // TODO Auto-generated method stub super.onUpdate(context, appWidgetManager, appWidgetIds); final int N = appWidgetIds.length; for (int i=0; i<N; i++) { int appWidgetId = appWidgetIds[i]; updateAppWidget(context, appWidgetManager, appWidgetId); } } 
+4
source share
1 answer

this is part of my code but you can get an idea

 @Override public void onEnabled(Context context) { super.onEnabled(context); AppWidgetManager appManager = AppWidgetManager.getInstance(context); ComponentName thisWidget = new ComponentName(context, ExampleAppWidgetProvider.class); RemoteViews updateViews = new RemoteViews(context.getPackageName(), R.layout.widget1); updateViews.setTextColor(R.id.widget1label, Color.YELLOW); appManager.updateAppWidget(thisWidget, updateViews); } 
+2
source

All Articles