Android : When do we use getIntent()?

Return the intent that started this activity.

If you start an Activity with some data, for example by doing

Intent intent = new Intent(context, SomeActivity.class);
intent.putExtra("someKey", someData);

you can retrieve this data using getIntent in the new activity:

Intent intent = getIntent();
intent.getExtra("someKey") ...

So, it’s not for handling returning data from an Activity, like onActivityResult, but it’s for passing data to a new Activity.

Leave a Comment