1

I have Aactivity.java and Bactivity.java.

Aactivity sends an Intent that passes the user to Bactivity.
Intent code:

Intent intent = new Intent(Aactivity.this, Bactivity.class);
startActivity(intent);

How can I get the name of the Intent sending activity's name (Aactivity in this case) and store it in a String?

EDIT #1:

I want to get a string with the activity who sent the intent to Bactivity.
So, if Aactivity sends an Intent to Bactivity, so I want that Bactivity will store a string with the word "Aactivity".

Ido Naveh
  • 2,442
  • 3
  • 26
  • 57
  • 1
    I'm not perfectly clear about the question.. But why can't you pass the name as an extra for the intent? – ashkhn Dec 09 '15 at 14:31
  • Because I don't want to check for extra because then, it will check for extra on every intent that I will do and I don't want it. – Ido Naveh Dec 09 '15 at 14:32
  • Can you elaborate why you cannot use extras? Otherwise the link posted by @MikeM. is what you're looking for I guess – ashkhn Dec 09 '15 at 14:54
  • read the doc. `getCallingActivity`. – njzk2 Dec 09 '15 at 14:54

2 Answers2

2

Put the sender activity's name as an extra too. For example:

intent.putExtra("ACTIVITY_NAME_BUNDLE_ID", "FancyActivityName");

And in the receiver activity's onCreate method handle this extra:

String senderActivityName = getIntent().getStringExtra("ACTIVITY_NAME_BUNDLE_ID");
Gex
  • 2,092
  • 19
  • 26
0

You can get the extra parameter of intent in the Bactivity's onCreate() as

String str= getIntent().getStringExtra("YOUR_KEY");
boolean bool = getIntent().getExtra("fourthSection" , false);

You can send the name of the Activity in the extra of intent by using putExtra but use the same key from every activity from which you calls BActivity...

rd7773
  • 409
  • 3
  • 13
  • It's not very clear. I'm looking for a way to filter the activities without using extra, because then it check this extra for every time the activity will open. – Ido Naveh Dec 09 '15 at 14:33
  • You can send the name of the Activity in the extra of intent by using putExtra but use the same key from every activity from which you calls BActivity... – rd7773 Dec 09 '15 at 14:40