问题描述
|
我的相机意图有些问题。据我所知,当相机方向改变时,活动会重新开始。 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());
}
捕获图片后,我按“完成”按钮,然后转到SaveFileActivity。一切正常,直到我尝试从SaveFIleActivity转到其他活动,然后相机重新启动。我应该在哪里寻找问题?也许我应该杀死相机意图,但是什么时候?
解决方法
我怀疑您想使用更简单的
startActivity()
和finish()
方法,而不是startActivityFromChild()
和finishFromChild()
。但是,我承认对于您实际使用的用途还是不太清楚。