我有3个活动:A,B和C.我想从A启动C并使用onActivityResult()
将结果发回给B:
startActivityForResult()
onActivityResult()
有可能吗?
答案 0 :(得分:1)
它不是直接可能的,因为当C结束时,活动C的结果将返回到活动A. 如果要在活动C将结果发送到A后打开活动B,则从onActivityResult启动活动B(当结果从C转到A时),使用A将从C接收的数据传递给B.
但如果您的活动B与上述不相关,则可以将活动C中的结果存储在SQLite DB中,然后在活动打开时从SQLite读取结果并显示在活动B中
答案 1 :(得分:0)
yes it is possible please do like this.
Intent intent=new Intent(MainActivity.this,ActivityC.class);
startActivityForResult(intent, 2);// Activity is started with
requestCode 2
@Override
protected void onActivityResult(int requestCode, int resultCode,
Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
// check if the request code is same as what is passed here
it is 2
if(requestCode==2)
{
String message=data.getStringExtra("MESSAGE");
textView1.setText(message);
//for here you can start your Activity B with data
whatever you want to send to Activity B.
}
}
和表单活动c设置结果如
Intent intent=new Intent();
intent.putExtra("MESSAGE",message);
setResult(2,intent);