0

I can take photos using default camera app. But just after getting image data within onActivityResult orientation changes and all data vanish (image data). I do not want to force users to use app in landscape mode.

so How can I store image path coming from camera intent even if orientation changes

@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
 if(resultCode==RESULT_OK) {
if (requestCode == CAPTURE) {

                if(Build.VERSION.SDK_INT<21){
                    lastPath=data.getStringExtra("path");
                }else{
                    lastPath=getRealPathFromURI(data.getData()) // set lastPath
                }
}

Then I try to store lastPath

@Override
protected void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);

    if(lastPath!=null){
        outState.putString("path",lastPath);

    }

}

Finally I try to get lastPath sent from onSaveInstanceState after restart of the app

 @Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
    super.onRestoreInstanceState(savedInstanceState);

    String path=savedInstanceState.getString("path");

    Log.v("path",path);

    // --> throws NullPointerException

}

as you see it throws Exception

Mustafa
  • 1
  • 3

0 Answers0