Activity myActivity  = AssumeSomeActivityExists();
    Intent openActivity = new Intent();
    openActivity.setAction(Intent.ACTION_VIEW);
    openActivity.setClass(myActivity,B.class);
    myActivity.startActivity(openActivity);


当我们执行上述操作时,如何使B实例知道它是由Activity myActivity调用和创建的?

最佳答案

与您的Intent搭配使用。

openActivity.putExtra("calledFromA", true)

然后在B中:

protected void onCreate(Bundle savedInstanceState) { {
    super.onCreate(savedInstanceState);
    boolean isCalledFromA = getIntent().getBooleanExtra("calledFromA", false);
}

关于android - Activity 到 Activity 的交流,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4046612/

10-09 09:33