Android 获取以前的活动 [英] Android get previous activity
本文介绍了Android 获取以前的活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有 2 个活动:Activity1
和 Activity2
.在每个活动中,都有一个按钮可将我引向第三个活动 (MainActivity
).在 MainActivity
中,我想知道从哪个活动页面被调用.
I have 2 activities: Activity1
and Activity2
.
In each of this activities there is a button that leads me to a third activity (MainActivity
). In MainActivity
I want to know from which activity page was called.
推荐答案
可以使用Intent的putExtra属性来传递Activity的名称.
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);
下一个活动,
Intent intent = getIntent();
String activity = intent.getStringExtra("activity");
现在在字符串活动中,您将获得它来自哪个活动的名称.
Now in the string activity you will get the name from which Activity it has came.
这篇关于Android 获取以前的活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文