Activity myActivity = AssumeSomeActivityExists();
Intent openActivity = new Intent();
openActivity.setAction(Intent.ACTION_VIEW);
openActivity.setClass(myActivity,B.class);
myActivity.startActivity(openActivity);
当我们执行上述操作时,如何让B
实例知道它已被活动myActivity
调用和创建?
答案 0 :(得分:2)
在你的意图中使用额外内容。
Smth喜欢openActivity.putExtra("calledFromA", true)
然后在B:
protected void onCreate(Bundle savedInstanceState) { {
super.onCreate(savedInstanceState);
boolean isCalledFromA = getIntent().getBooleanExtra("calledFromA", false);
}