Passing data from widget to app
===

I'm developing a widget for my app that passes some data from the widget to my app, since the user can add multiple widgets, I want pass certain data, detect it in the app and show perform certain actions based on the data passed from the widget.

What I have works, for the most part, however, it only works, if I exit my app completely.  If I press on the widget, my app displays with the correct data, but if I press home and press on another widget that was created, the app doesn't seem to detect the data being passed to it.  Only hitting the back button over and over until the app exits completely seem to work.

This the code I have to pass the data from the widget to the app:

	public class WidgetProvider extends AppWidgetProvider  {

		public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
			
			final int N = appWidgetIds.length;

			for (int i=0; i<N; i++) 
				UpdateWidget(context, appWidgetManager, appWidgetIds[i]);
		}
		
		public static void UpdateWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId)
		{
			Intent intent = new Intent(context, Main.class);
			final Bundle bun = new Bundle();
			bun.putInt("widgetId", appWidgetId);
			intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
			intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
			intent.putExtras(bun);

			PendingIntent pendingIntent = PendingIntent.getActivity(context, appWidgetId, intent, PendingIntent.FLAG_UPDATE_CURRENT);

			RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget);
			views.setOnClickPendingIntent(R.id.widgetText, pendingIntent);
			
			appWidgetManager.updateAppWidget(appWidgetId, views);
		}
	}
