Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the name of calling activity?

Tags:

android

I want to retrive the name of the calling activity for checking some conditions.. What will be the solution?

like image 464
Ranjit Avatar asked Dec 16 '22 04:12

Ranjit


2 Answers

I think you can achieve this even with getCallingActivity().getClassName()

like image 99
Olsi Saqe Avatar answered Feb 07 '23 09:02

Olsi Saqe


You can send data between activities using Bundle

Have a look at this example: http://www.balistupa.com/blog/2009/08/passing-data-or-parameter-to-another-activity-android/

Basically you need to put the name of the caller as parameter:

Bundle bundle = new Bundle();
bundle.putString(this.class.getName(), “ClassName”);

Intent newIntent = new Intent(this.getApplicationContext(), ActivityClass2.class);
newIntent.putExtras(bundle);
startActivityForResult(newIntent, 0);

And in ActivityClass2, you can read this parameter using:

Bundle bundle = this.getIntent().getExtras();
String className = bundle.getString(“ClassName″);
like image 32
Caner Avatar answered Feb 07 '23 09:02

Caner