Android,从其他活动中获取结果然后开始

时间:2013-02-16 11:56:57

标签: android android-camera

我正在尝试创建自己的相机活动(一个拍照,第二个显示)。 问题是,我首先开始“takePictureActivity”,所以我会得到这个Activity的结果。但我想从“ShowPictureActivity”获得结果。有人可以建议我如何让它有效吗?

a busy cat http://img248.imageshack.us/img248/1783/imgqtd.png

MainActivity:

    Intent intent = new Intent(this , TakePictureActivity.class);
     startActivityForResult(intent,  TAKE_PICUTRE);  

TakePictureActivity:

      Itent intent = new Intent(this , ShowPictureActivity.class);
      intent.putExtras(image_data);
      startActivity(intent);

ShowPictureActivity:

         Intent _result = new Intent();              
    _result.setData(image_data);
   setResult(Activity.RESULT_OK, _result);

1 个答案:

答案 0 :(得分:1)

TakePictureActivity (仅限伪代码)

使用startActivityForResult(intent, Result_OK);代替startActivity(intent);启动 ShowPictureActivity

现在,在 TakePictureActivity 中实施onActivityResult()

onActivityResult()
{
 if(resultCode == RESULT_OK)
 { 
     // Back from ShowPictureActivity with Result 
     // Set Result for your MainActivity:
     setResult();
     finish();
  }
}

这会将结果发送到 MainActivity onActivityResult()