相机意图问题,相机正在启动而没有请求

时间:2011-06-04 01:13:26

标签: android android-camera-intent

我的相机意图有点问题。据我所知,当相机方向改变时,活动重新开始。 Okej,我正在使用下面的代码。

    @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    app = (myApplication)getApplication(); 

    if(savedInstanceState ==null ) getFullImage(null);
    else{
        String somevalue = savedInstanceState.getString("uri");
        getFullImage(somevalue);
        }
}

private void getFullImage(String testValue)
{   if(testValue == null){
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    file = new File(Environment.getExternalStorageDirectory(), UUID.randomUUID()+ ".jpg");
    outputFile = Uri.fromFile(file);
    intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFile);
    startActivityForResult(intent, TAKE_PICTURE);

}else 
{   
    outputFile = null;
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    file = new File(testValue);
    outputFile = Uri.fromFile(file);
    intent.putExtra(MediaStore.EXTRA_OUTPUT, testValue);
    startActivityForResult(intent, TAKE_PICTURE);
    finishFromChild(getParent());
}

}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if(resultCode == RESULT_CANCELED) {
        Log.i(TAG, "Back Button"); 
        finishFromChild(this);
    } 
    else
     if(requestCode == TAKE_PICTURE && resultCode == RESULT_OK)
        {   
    //I'm creating new file here (for this question is irelevant)
        } catch (IOException e) {

            e.printStackTrace();
        }

        Intent myIntent = new Intent(getBaseContext(), com.test.activities.SaveFileActivity.class);
        myIntent.putExtra("image", newPath);
        startActivityFromChild(this, myIntent, SAVE_ITEM);  
        finishFromChild(this);
    }

}

@Override
protected void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    outState.putString("uri",outputFile.getPath());
}

拍下照片后,按DONE按钮,我转到SaveFileActivity。一切正常,直到我尝试从SaveFIleActivity转到另一个活动,然后相机再次启动。我应该在哪里寻找问题?也许我应该杀掉相机意图,但什么时候?

1 个答案:

答案 0 :(得分:0)

我怀疑您希望使用更简单的startActivity()finish()方法,而不是startActivityFromChild()finishFromChild()。不过,我承认,我对你实际使用的内容有点不清楚。