对活动沟通的活动

时间:2010-10-28 19:45:50

标签: android android-activity communication android-intent

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

当我们执行上述操作时,如何让B实例知道它已被活动myActivity调用和创建?

1 个答案:

答案 0 :(得分:2)

在你的意图中使用额外内容。

Smth喜欢openActivity.putExtra("calledFromA", true)

然后在B:

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