I have a widget that launches an activity, but when the activity finishes using the finish() I don’t know how my widget can know about it since I can’t override onActivityResult() which seems like the only way to listen when an activity closes…
Anyone know of another way to listen for when an Activity closes when it is a widget that launches the Activity?
In case it helps, here is the code I’m using in my widget to launch the Activity
@Override
public void onUpdate(Context context,
AppWidgetManager appWidgetManager, int[] appWidgetIds) {
Intent i = new Intent(context, ChooseContact.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context,0,i,0);
RemoteViews updateViews = new RemoteViews(context.getPackageName(), R.layout.main);
updateViews.setOnClickPendingIntent(R.id.button, pendingIntent);
appWidgetManager.updateAppWidget(appWidgetIds, updateViews);
// Not really necessary, just a habit
super.onUpdate(context, appWidgetManager, appWidgetIds);
}
As you said, it’s better for the Activity to update the widget. You can override the onStop method of the Activity, and send an Intent to the widget to ask it to redraw… something like this: