0

我的相机意图有点问题。据我所知,当相机方向改变时,活动会重新启动。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。Everyting 工作正常,直到我尝试从 SaveFIleActivity 转到另一个活动,然后相机再次启动。我应该在哪里寻找问题?也许我应该杀死相机意图,但是什么时候?

4

1 回答 1

0

我怀疑您想使用更简单的startActivity()andfinish()方法而不是startActivityFromChild()and finishFromChild()。但是,我承认,对于您实际用于什么用途,我有点不清楚。

于 2011-06-04T02:57:31.040 回答