3

I noticed very strange behaviour of my device.

I create a new intent with action MediaStore.ACTION_IMAGE_CAPTURE

Then I start an activty for result. But at the moment I take a picture from the camera my application disappears from processes in DDMS perspective. Then in few seconds it is running again.

What is interesting - onActivityResult is called properly and receives an image. But I have some singletones that contain some values in their fields. After process is restarted these singletones are re-initialized and lose all values.

There is no problem on other devices - neither tablets nor phones.

Is it a known bug? Ho to prevent process restarting on Galaxy Tab 2 10.1?

Thanks in advance!

UPDATE: Below is my code that starts camera intent

private void startCameraIntent() {
    String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.US).format(new Date());
    String imageFileName = JPEG_FILE_PREFIX + timeStamp + "_";
    File albumFile;
    if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())){
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO){
            albumFile = new File (Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), FOLDER_NAME);
        } else {
            albumFile = new File(Environment.getExternalStorageDirectory()+CAMERA_DIR+FOLDER_NAME);
        }
        if (albumFile != null){
            if (!albumFile.mkdirs()){
                if (!albumFile.exists()){
                    showToast(getApplicationContext().getString(R.string.sFailedToCreateDirectory));
                    return;
                }
            }
        }
        File imageFile = null;
        try {
            imageFile = File.createTempFile(imageFileName, JPEG_FILE_SUFFIX, albumFile);
            mCurrentPhotoPath = imageFile.getAbsolutePath();
        } catch (IOException e) {
            e.printStackTrace();
        }
        Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(imageFile));
        fileUri = Uri.parse(mCurrentPhotoPath);

        startActivityForResult(cameraIntent, ACTION_CAPTURE_IMAGE);
    } else {
        showToast(getApplicationContext().getString(R.string.sSDNotReady));
    }
}
Carlos
  • 349
  • 1
  • 3
  • 17

1 Answers1

1

Is it a known bug?

It is not a bug. If your app is not in the foreground, its process can be terminated at any time.

Ho to prevent process restarting on Galaxy Tab 2 10.1?

You can't. Your process can go away at any time when it is not in the foreground. So, for example, if the user presses HOME, and later Android terminates your process, and after that the user tries returning to your app via the recent-tasks list, you will see the same behavior. Your app needs to be able to handle this.

You are welcome to try working with the Camera directly, rather than starting the third-party activity, as that will keep your app in the foreground. This is more complex than what you are doing, though.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491