Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getIntent().getExtras() passes null values in OnActivityResult

Tags:

android

I am passing a context from an activity-A to a page adapter and inside that adapter i am passing an intent to make a call

 Intent intent = new Intent(Intent.ACTION_CALL);
                        intent.setData(Uri.parse("tel:" + number));
                        intent.putExtra("id",listId.toString());
                        context.startActivityForResult(intent, 105);

The Activity A is inherited from another Activity B and inside that base Activity B, onActivityResult is defined as:

@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    super.onActivityResult(requestCode, resultCode, intent);

    if (requestCode == 104) {
        if (GetLocation.isLocationEnabled(this)) {
            <my codes>
        }
    }
}

Inside Activity A i am having onActivityResult as:

@Override
 public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    super.onActivityResult(requestCode, resultCode, intent);

    if (requestCode == 105) {

        Bundle extras=getIntent().getExtras();
        String user_Id=extras.getString("id");         
    }
}

I am always getting a null value for user_Id, Can anyone help me on this issue?

like image 709
Hari Krishnan Avatar asked Oct 08 '15 13:10

Hari Krishnan


1 Answers

use intent.getExtras() instead of getIntent().getExtras()

getIntent() will get you the intent which launched your activity originally.

like image 159
Rahul Tiwari Avatar answered Sep 30 '22 16:09

Rahul Tiwari