怎样才能知道一个屏幕是从哪个屏幕打开的。例如: screen1和screen2可以转到(意图) screen3。在screen3中如何查找来自screen1或screen2的用户?
谢谢
发布于 2011-11-07 17:35:31
使用putExtra()和getStringExtra()来解决您的问题。喜欢
在Screen1 Activity中编写以下代码
Intent intent = new Intent().setClass(Screen1.this, Screen3.class);
intent.putExtra("caller", "Screen1");
startActivity(intent);在Screen2 Activity中,编写以下代码
Intent intent = new Intent().setClass(Screen2.this, Screen3.class);
intent.putExtra("caller", "Screen2");
startActivity(intent);现在在Screen3 Activity的onCreate()上
String caller = this.getIntent().getStringExtra("caller");
if(caller != null) {
if("Screen1".equalsIgnoreCase(caller)) {
Toast.makeText(this, "Called from screen 1", Toast.LENGTH_SHORT).show();
} else if("Screen2".equalsIgnoreCase(caller)){
Toast.makeText(this, "Called from screen 2", Toast.LENGTH_SHORT).show();
}
}希望这能澄清..。
发布于 2011-11-07 17:28:35
使用此方法从parrent返回activity类
GetParent()然后是像getId()或getTag()之类的东西,或者可以确定它是屏幕1还是屏幕2的东西。
https://stackoverflow.com/questions/8034518
复制相似问题