doneButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(!imgUriList.isEmpty())
{
Intent intent = new Intent(getBaseContext(), createAdActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP|Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, imgUriList);
startActivity(intent);
}
}
});
This is the code I have used in my second activity to send extras to the first activity.
I want to keep the first activity as it is when coming back from the second activity. Therefore I have used _SINGLE_TOP,CLEAR_TOP FLAGS.
Without the Flags it works well. But After using the extras extras become null. This is the Code I have used in my first activity.
@Override
protected void onResume() {
super.onResume();
Toast.makeText(this,"IN RESUME ",Toast.LENGTH_LONG).show();
imageUris = getIntent().getParcelableArrayListExtra(Intent.EXTRA_STREAM);
if(getIntent().hasExtra(Intent.EXTRA_STREAM)) {
if (!imageUris.isEmpty()) {
createAdViewPagerAdapter viewpager = new createAdViewPagerAdapter(this,imageUris);
photoViewer.setAdapter(viewpager);
}
}
}
Since the first activity also uses some extras sent from MainActivity I have overrides the onNewIntent()method as well.
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
}
With getIntent() you will get the old Intent you need to process the intent argument of onNewIntent(). You can use setIntent(intent) it will Change the intent returned by getIntent(). To make sure any further call to getIntent() will return the latest intent use setIntent()
.
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
setIntent(intent);
// Do further stuff here
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With