Enviar datos del widget a la actividad
Estoy tratando de enviar datos desde mi widget a mi actividad. He visto varios temas sobre el lado del widget, pero no logré obtener los datos en mi actividad.
VerTransmitir datos del widget a la aplicación
En mi actividad intento hacer en el método onStart ():
Intent intent = getIntent();
if(intent.getStringExtra("he")!=null)
LogWrapper.debug(MainActivity.class, "DATA "+intent.getStringExtra("he"));
else
LogWrapper.debug(MainActivity.class, "DATA null");
Pero la intención es siempre nula.
Lado del proveedor de widgets:
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
super.onUpdate(context, appWidgetManager, appWidgetIds);
LogWrapper.info(DefibWidgetProvider.class,"in onUpdate!");
final int N = appWidgetIds.length;
// Perform this loop procedure for each App Widget that belongs to this provider
for (int i=0; i<N; i++) {
int appWidgetId = appWidgetIds[i];
// Create an Intent to launch MainActivity
Intent intent = new Intent(context, MainActivity_.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra("he","Hello !");
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
// Get the layout for the App Widget and attach an on-click listener
// to the button
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_defib);
views.setOnClickPendingIntent(R.id.refreshButton, pendingIntent);
// Tell the AppWidgetManager to perform an update on the current app widget
appWidgetManager.updateAppWidget(appWidgetId, views);
}
}
Contexto: mi aplicación contiene un mapa de Google. Tengo 2 botones en mi widget, y quiero abrir la actividad y centrar el mapa en un largo / lat especial cuando el usuario hace clic en uno de estos botones.
¿Podrías ayudarme a hacer que esto funcione? gracias