0

I have three Activity classes,

1.MainActivity

2.firstActivity

3.SecondActivity

In Activity classes interactions are MainActivity->FirstActivity->SecondActivity

I want to retrive the name of the calling activity for knowing activity names and activity flows and for other works.

RaMeSh
  • 3,330
  • 2
  • 19
  • 31
  • How does you start your activity? By using startActivityForResult? – Pankaj Kumar Apr 27 '15 at 06:54
  • I'm not using that,i'm using like startActivity(intent); – RaMeSh Apr 27 '15 at 06:55
  • 2
    You really shouldn't. Providing different behavior in a function based on where you were called from is considered VERY bad design. You should either use different functions or pass down the behavior you want in the arguments (although even that can become an antipattern quickly). – Gabe Sechan Apr 27 '15 at 06:56
  • 1
    You can send the Activity name through `intent.putString("key","Here activity name")` and retrive the activity name through by its key `intent.getString("key")`; – Yuva Raj Apr 27 '15 at 06:56
  • Look into http://stackoverflow.com/questions/4967799/how-to-know-the-calling-activity-in-android This might duplicate – Pankaj Kumar Apr 27 '15 at 06:57
  • @PankajKumar i have not seen that you are posted link,this question is just my thought. – RaMeSh Apr 27 '15 at 07:01
  • @User Duplicate means similar question with answer. So I am not saying that you are doing somthing dulicate of others :) – Pankaj Kumar Apr 27 '15 at 13:21

2 Answers2

0

While starting Activity use

Intent intent = new Intent(CallicingActivity.this , CalledActivity.class);
intent.putString("callingActivityname","CallicingActivity");
startActivity(intent);

and get the Activityname

    Bundle extras =  getIntent().getExtras();
    String _callingallingActivityName = extras.getString("callingActivityname");
Subhalaxmi
  • 5,687
  • 3
  • 26
  • 42
0

After many trails i have done this.

Get the Activity Name

 Intent intent = getIntent();
 String activity = intent.getStringExtra("activity");
 Toast.makeText(getApplicationContext(), activity,  Toast  .LENGTH_LONG).show();

Calling Next Activity

 Intent intentNew = new Intent(this, Activity2.class);
 intentNew.putExtra("activity", "Activity2");
 startActivity(intentNew);
RaMeSh
  • 3,330
  • 2
  • 19
  • 31