Apoorv Gupta
Apoorv Gupta

Reputation: 102

intent.putExtra() and intent.getStringExtra() are not working. getStringExtra returns null

intent.putExtra() and intent.getStringExtra() are not working. getStringExtra returns null

At sending side:

             Intent intent = new Intent(getApplicationContext(), ChooseUserActivity.class);
             startActivity(intent);

             intent.putExtra("Name",imageName);

At receiving side:

            Intent secondIntent = getIntent();
            String nameImage = "Something " + secondIntent.getStringExtra("Name");
            Log.i("Name of the Image: ",nameImage);

The output of the Log cat:

enter image description here

Upvotes: 1

Views: 259

Answers (1)

hamid_c
hamid_c

Reputation: 849

You should first put Extras in Intent and then start activity not after it

//create intent
Intent intent = new Intent(getApplicationContext(),ChooseUserActivity.class);

//put extras
intent.putExtra("Name",imageName);

//start activity
startActivity(intent);

Upvotes: 1

Related Questions