user1242192
user1242192

Reputation: 261

onActivityResult return null getExtra value after return back from permission dialogue

Here is my code: final Intent intent = new Intent(this, SelectWidgetActivity.class); startActivityForResult(intent, REQUEST_CREATE_APPWIDGET);

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {

    if (resultCode == RESULT_OK ) {
        String selectedName = data.getStringExtra(SelectWidgetActivity.SELECTED_WIDGET);
        if(!mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId, info.provider)) {
                    Intent bindIntent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
                    bindIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
                    bindIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.provider);
                    bindIntent.putExtra(SelectWidgetActivity.SELECTED_WIDGET, selectedName);
                    startActivityForResult(bindIntent, REQUEST_BIND_APPWIDGET);
        }
    }
}

I put String on the first call of startActivityForResult and on the second call I'm trying to get the same string, but getting null. For example on the first call selectedName="Calendar", the second call onActivityResult() selectedName=null

Any ideas?

Upvotes: 0

Views: 245

Answers (1)

Anirudh Goud
Anirudh Goud

Reputation: 346

you must be even checking for the requestCode in onActivityResult that you send when you are making this call

startActivityForResult(intent, REQUEST_CREATE_APPWIDGET);

Try this

  if (requestCode == REQUEST_CREATE_APPWIDGET && resultCode == Activity.RESULT_OK) {
        //do your work here;
    }

Upvotes: 3

Related Questions