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?.
Asked
Active
Viewed 1,130 times
2 Answers
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
-
From: http://stackoverflow.com/questions/8119526/android-get-previous-activity – Adam Arold May 30 '13 at 13:50
-
I was thinking the same thing. So I guess there is no method/class. – wesdfgfgd May 30 '13 at 13:52
-
No built in method sadly. – Adam Arold May 30 '13 at 13:53
-
What about the back stack? – Phil Haigh May 30 '13 at 14:02
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