Android的GET previous活动Android、GET、previous

2023-09-12 04:17:11 作者:爆炸小公举

我有2个活动(活动1,活性2) 在每一个这样的活动是谁使我第三个活动按钮(MainActivity) 在MainActivity我想知道从哪个活动页面被调用。

I have 2 activities (Activity1, Activity2) In each of this activities is a button who lead me to a third activity (MainActivity) In MainActivity i want to know from which activity page was called.

推荐答案

您可以使用意向的putExtra属性传递活动的名称。

You can use the putExtra attribute of the Intent to pass the name of the 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.