我创建了 3 个活动。活动 A 为结果启动了活动 B,而活动 B 则简单地启动了活动 C 并在自身上调用了 finish()。活动 C 启动后,将结果设置为 A 想要的任何内容,并在 self 上调用完成。活动 A 中的 onActivityResult 被调用,所以我相信答案是肯定的,可以做到。
这是我的示例活动
活动 A:
public class MainTestActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_test);
new Timer().schedule(new TimerTask() {
@Override
public void run() {
// TODO Auto-generated method stub
Intent in = new Intent(MainTestActivity.this, TestActivityB.class);
startActivityForResult(in, 101);
}
}, 2000);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main_test, menu);
return true;
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
Toast.makeText(this, "Got Intent", Toast.LENGTH_SHORT).show();
}
}
活动 B:
public class TestActivityB extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_test);
new Timer().schedule(new TimerTask() {
@Override
public void run() {
// TODO Auto-generated method stub
Intent in = new Intent(TestActivityB.this, TestActivityC.class);
startActivity(in);
finish();
}
}, 2000);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main_test, menu);
return true;
}
}
活动 C:
public class TestActivityC extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_test);
new Timer().schedule(new TimerTask() {
@Override
public void run() {
// TODO Auto-generated method stub
setResult(101);
finish();
}
}, 2000);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main_test, menu);
return true;
}
}