Reputation: 21
I need to use onActivityResult
in widget that launch activity
public class MainActivity extends AppWidgetProvider implements
OnActivityResultListener {
Context context;
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
int[] appWidgetIds) {
super.onUpdate(context, appWidgetManager, appWidgetIds);
this.context = context;
for (int i = 0; i < appWidgetIds.length; i++) {
int appWidgetId = appWidgetIds[i];
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE);
PendingIntent pending = PendingIntent.getActivity(context, 0, intent, 1);
RemoteViews views = new RemoteViews(context.getPackageName(),
R.layout.activity_main);
views.setOnClickPendingIntent(R.id.imageButton1, pending);
appWidgetManager.updateAppWidget(appWidgetId, views);
}
}
@Override
public boolean onActivityResult(int requestCode, int resultCode, Intent data) {
}
I need that when I select contact can get result on the widget
Upvotes: 0
Views: 1350
Reputation: 917
In your manifest, add a new intent filter in your appwidget's broadcast and add a personnal action to it like "GET_RESULT_FROM_ACTIVITY", then launch your activity from which you want result. when you are done with your code, call sendBroadcast(your_intent) method in this activity with an intent in which you put your extras and on which you set your action "GET_RESULT_FROM_ACTIVITY". In your onReceive() method of your appwidget, check if intent.getAction().equals("GET_RESULT_FROM_ACTIVITY") and do what you want in your if statement.
Upvotes: 1
Reputation: 761
It is wrong that because AppWidgetProvider has not the method onActivityResult.
@Override
public boolean onActivityResult(int requestCode, int resultCode, Intent data) {
}
IF you want to get result from an activity,you can use send Broadcast to update the appwidget views
Upvotes: 0
Reputation: 32680
Assuming you passed data back from the second activity via Intent.putExtra()
, you can access whatever you're passing by calling data.getExtras()
in your onActivityResult
method.
See tutorial here.
Upvotes: 0