Camera intent problem, camera is starting without request
I have a little problem with my camera intent. As I know, when camera orientation is changed, activity is restarted. Okej, I am using the code bellow.
@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);
}
}
@Overr开发者_JS百科ide
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putString("uri",outputFile.getPath());
}
After picture is captured, I press DONE button and I go to SaveFileActivity. Everyting works fine, until I try from SaveFIleActivity to go to another activity, then camera is starting again. Where should I look for the problem ? Maybe I should kill camera intent, but when ?
I suspect you want to be using the simpler startActivity()
and finish()
methods instead of startActivityFromChild()
and finishFromChild()
. I admit, however, that I'm a bit unclear as to what the use of the ones you are actually for.
精彩评论