I have 2 activities: Activity1
and Activity2
. In each of this activities there is a button that leads me to a third activity (MainActivity
). In MainActivity
I want to know from which activity page was called.
You can use the putExtra attribute of the Intent to pass the name of the Activity.
Calling Activity,
Intent intent = new Intent(this, Next.class); intent.putExtra("activity","first"); startActivity(intent);
Next Activity,
Intent intent = getIntent(); String activity = intent.getStringExtra("activity");
Now in the string activity you will get the name from which Activity it has came.
You can use:
public ComponentName getCallingActivity()
to know which Activity called your current Activity
.
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