android屏幕跟踪

android屏幕跟踪,android,android-activity,android-intent,Android,Android Activity,Android Intent,如何从哪个屏幕知道屏幕打开。例如:screen1和screen2可以转到(意图)screen3。在屏幕3中,如何从屏幕1或屏幕2查找用户 感谢使用此方法从parrent返回活动类 GetParent() 然后是诸如getId()或getTag()之类的东西,或者可以确定它是屏幕1还是屏幕2。使用putExtra()和getStringExtra()来解决您的问题。 像 在屏幕1活动中编写此代码 Intent intent = new Intent().setClass(Screen1.thi

如何从哪个屏幕知道屏幕打开。例如:screen1和screen2可以转到(意图)screen3。在屏幕3中,如何从屏幕1或屏幕2查找用户


感谢使用此方法从parrent返回活动类

GetParent()
然后是诸如getId()或getTag()之类的东西,或者可以确定它是屏幕1还是屏幕2。

使用
putExtra()
getStringExtra()
来解决您的问题。 像

屏幕1活动中
编写此代码

 Intent intent = new Intent().setClass(Screen1.this, Screen3.class);
         intent.putExtra("caller", "Screen1");
         startActivity(intent);
 Intent intent = new Intent().setClass(Screen2.this, Screen3.class);
         intent.putExtra("caller", "Screen2");
         startActivity(intent);
屏幕2活动中
,编写以下代码

 Intent intent = new Intent().setClass(Screen1.this, Screen3.class);
         intent.putExtra("caller", "Screen1");
         startActivity(intent);
 Intent intent = new Intent().setClass(Screen2.this, Screen3.class);
         intent.putExtra("caller", "Screen2");
         startActivity(intent);
现在开始
Screen3活动的
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();
            }
        }
希望这一切都会过去