Sriram R
Sriram R

Reputation: 2229

Intent getStringExtra returning null

I know this question has been asked a lot, but I have no idea where I went wrong..

So I sent some data through one activity and retrieving it from the other activity.

FirstActivity

Timber.i("Photo img : %s", posterUrl);
    String url = AppConstants.IMAGE_BASE_URL+ 
    AppConstants.POSTER_SIZE_ORIGINAL+ posterUrl;
    Intent i = new Intent(this, ImageFullActivity.class);
    i.putExtra(AppConstants.IMAGE_URL, url);
    startActivity(i);

Recieving Activity

Intent i = new Intent();
String imageUrl = i.getStringExtra(AppConstants.IMAGE_URL);    
Timber.i("GOt image url %s", imageUrl);
Picasso.with(this)
      .load(imageUrl)
      .into(image);

And I checked. I am not passing null through the extras. The posterUrl is a valid string.

Upvotes: 1

Views: 378

Answers (4)

Durga M
Durga M

Reputation: 544

Problem is that you are trying to create new intent in your receiving activity which does not have your data what you passed in other activity. To get the intent what you passed in other activity use getIntent().

Intent i = getIntent();

Here this intent will be holding your data you passed from other activity.

Upvotes: 0

Ratilal Chopda
Ratilal Chopda

Reputation: 4220

Try this

//Intent i = new Intent();
String imageUrl = getIntent().getStringExtra(AppConstants.IMAGE_URL);    
Timber.i("GOt image url %s", imageUrl);
Picasso.with(this)
      .load(imageUrl)
      .into(image);

OR

Bundle bundle = getIntent().getExtras();
String imageUrl = bundle.getString(AppConstants.IMAGE_URL);
Timber.i("GOt image url %s", imageUrl);
Picasso.with(this)
      .load(imageUrl)
      .into(image);

Upvotes: 1

user7810812
user7810812

Reputation:

String imageUrl = getIntent().getStringExtra(AppConstants.IMAGE_URL);

You need to get the intent by getIntent() method

Upvotes: 0

Pavneet_Singh
Pavneet_Singh

Reputation: 37404

You need to use getIntent() to get the intent instance that started the next activity as

 getIntent().getStringExtra

instead of creating a new empty one

//Intent i = new Intent(); remove

Intent i = getIntent(); // or do this

Upvotes: 4

Related Questions