androidandroid-cameraandroid-14

API Level 34 (Android 14) camera application calling onDestroy method abruptly


In Samsung A14 5G (android 14) camera app is calling on destroy method of the calling fragment and activity abruptly.

I have already added config changes code in manifest.

android:configChanges="orientation|keyboardHidden|screenSize"

Code to launch camera :

public static File openCamera(Context mContext, Fragment currentFragment) {
        if (ActivityCompat.checkSelfPermission(mContext, Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED) {
            Log.d(TAG, "opening camera");
            String imageName = dateToString(new Date(), PhotoConstant.IMAGE_NAME_FORMAT);
            File filePath = new File(mContext.getExternalFilesDir(""), PhotoConstant.IMAGE_DIR);
            //File filePath = new File(PhotoConstant.IMAGES_DEFAULT_PATH, PhotoConstant.IMAGE_DIR);
            if (!filePath.exists()) {
                Log.e(TAG, "folder not exist, going to create new folder");
                filePath.mkdir();
            }

            File destinationFile = new File(
                    mContext.getExternalFilesDir(""),
                    imageName + PhotoConstant.IMAGE_FORMAT);
            //  File destinationFile = new File(PhotoConstant.IMAGES_DEFAULT_PATH + File.separator + PhotoConstant.IMAGE_DIR, imageName + PhotoConstant.IMAGE_FORMAT);
            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
//      intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(destinationFile));
            intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
            intent.putExtra(MediaStore.EXTRA_OUTPUT, AppUtil.getFileUri(mContext, destinationFile));
            currentFragment.startActivityForResult(intent, PICK_Camera_IMAGE);
            Log.d(TAG, "name of image to be capture " + imageName);
            return destinationFile;
        }else{
            Toast.makeText(mContext,"Please Grant Camera Permission in Setting!",Toast.LENGTH_SHORT).show();
        return null;
        }

        }



public static Uri getFileUri(Context mContext, File destination) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            return FileProvider.getUriForFile(mContext,
                    mContext.getApplicationContext()
                            .getPackageName() + ".provider", destination);
        } else {
            return Uri.fromFile(destination);
        }
    }

Solution

  • Your app can have its process terminated at any point when its UI is in the background. This includes cases where you launch another app, such as the camera app, and it comes to the foreground. This is perfectly normal and is the way that Android has worked since Android 1.0 back in 2008.