Android Start new activity with data


Intent intent = new Intent(getBaseContext(), SignoutActivity.class);
intent.putExtra("EXTRA_SESSION_ID", sessionId);
startActivity(intent);

Access that intent on next activity

String sessionId= getIntent().getStringExtra("EXTRA_SESSION_ID");

to check if data is null

if( getIntent().getExtras() != null)
{
//do here
}

394

You have a few options:

1) Use the Bundle from the Intent:


Intent mIntent = new Intent(this, Example.class);
Bundle extras = mIntent.getExtras();
extras.putString(key, value);

2) Create a new Bundle


Intent mIntent = new Intent(this, Example.class);
Bundle mBundle = new Bundle();
mBundle.putString(key, value);
mIntent.putExtras(mBundle);

3) Use the putExtra() shortcut method of the Intent


Intent mIntent = new Intent(this, Example.class);
mIntent.putExtra(key, value);

Then, in the launched Activity, you would read them via:

String value = getIntent().getExtras().getString(key)

Leave a Reply

Your email address will not be published. Required fields are marked *

five × 2 =