Consegui uma forma da seguinte maneira
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
System.out.println("onUpdate");
final int N = appWidgetIds.length;
RemoteViews views;
for (int i=0; i<N; i++) {
int appWidgetId = appWidgetIds[i];
SharedPreferences dados = context.getSharedPreferences(MontWidget, 0);
Integer posicao = dados.getInt(ID_CONFIG_WIDGET+appWidgetId, 0);
Log.i("Posicao de selecao", String.valueOf(posicao));
if (posicao == 0) {
CharSequence widgetText = WidgetConfigActivity.loadTitlePref(context, appWidgetId);
views = new RemoteViews(context.getPackageName(), R.layout.x1);
Intent confirmar_acao = new Intent(context, Alert_x1_Activity.class);
confirmar_acao.putExtra(Alert_x1_Activity.ARG_DIALOG_NUMBER, 1);
confirmar_acao.putExtra("KEY_ID",appWidgetId);
confirmar_acao.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
PendingIntent confirmar_acao_u = PendingIntent.getActivity(context,
appWidgetId, confirmar_acao, PendingIntent.FLAG_UPDATE_CURRENT | 0);
views.setOnClickPendingIntent(R.id.btn_x1, confirmar_acao_u);
views.setOnClickPendingIntent(R.id.txt_x1, confirmar_acao_u);
views.setTextViewText(R.id.txt_x1,widgetText);
appWidgetManager.updateAppWidget(appWidgetId, views);
}
if(posicao == 1) {
CharSequence widgetText = WidgetConfigActivity.loadTitlePref(context, appWidgetId);
views = new RemoteViews(context.getPackageName(), R.layout.x2_widget);
Intent confirmar_acao = new Intent(context, Alert_x2_Activity.class);
confirmar_acao.putExtra(Alert_x2_Activity.ARG_DIALOG_NUMBER, 1);
confirmar_acao.putExtra("KEY_ID",appWidgetId);
confirmar_acao.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
PendingIntent confirmar_acao_u = PendingIntent.getActivity(context,
appWidgetId, confirmar_acao, PendingIntent.FLAG_UPDATE_CURRENT | 0);
views.setOnClickPendingIntent(R.id.btn_x2, confirmar_acao_u);
views.setOnClickPendingIntent(R.id.txt_painel_virtual, confirmar_acao_u);
views.setTextViewText(R.id.txt_x2,widgetText);
appWidgetManager.updateAppWidget(appWidgetId, views);
}
}
}
Pode ser feito dessa maneira
Obs: Alert_x1_Activity abre um AlertDialog de confirmação
No meu exemplo devo chamar os id do AppWidget nas classes Alertx1 ou Alertx
int widgetId = getIntent().getIntExtra("KEY_ID", -1);