0

When entering a preference activity or an option screen, I want to be able to know what was the previous activity. Is there some built in method or class to know which activity was before the current activity/ preference activity you are in?.

Edward Falk
  • 9,991
  • 11
  • 77
  • 112
wesdfgfgd
  • 683
  • 1
  • 13
  • 26

2 Answers2

2

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.

Adam Arold
  • 29,285
  • 22
  • 112
  • 207
0

You could do that without a Bundle...

Activity A starts Activity B over this Method of Activity B.

public class B extends Activity{

     private static String previousActivity;

     public static start(Context ctx, String prevAct){
         previousActivity = prevAct;
         Intent i = new Intent(ctx,currentActivity.class);
         ctx.startActivity(i);
     }
...
Luser_k
  • 514
  • 1
  • 4
  • 18