Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add parameters to intent on launch

I'm pretty sure there was a way to add parameters to intent on launch of app from android studio (simulate opened from push notification).

Do you know how to do it?

like image 679
Lena Bru Avatar asked Nov 18 '25 23:11

Lena Bru


2 Answers

You are right. It is completely possible. If you check the am command's help, you will see that we can pass arguments using -e.

enter image description here

So, follow these steps:

1. Edit launch configurations:

enter image description here

2. Add the desired arguments in the Launch Flags box, then press Apply and OK:

enter image description here

3. Now the passing argument will be available in the launcher activity's extras:

enter image description here

like image 139
aminography Avatar answered Nov 20 '25 12:11

aminography


I assume you handle the intent yourself.

In this case it's always possible to add an Extra to an Intent, as long as the object you try to pass a parameter is either implements Parcelable or Serializable.

So your process could look like:

In the activity starting class

Intent launch = new Intent(this, NewActivity.class);
launch.putExtra("parcelable", new ParcelableObject());
startActivity(launch);

In the new activity

Intent from = getIntent();
ParcelableObject pojo = from.getParcelableExtra("parcelable");
like image 24
vMysterion Avatar answered Nov 20 '25 12:11

vMysterion