I have MainActivity in which I can launch camera application to take and upload photo. After home long press while in camera app and returning back from recents I return to camera application. How can I ALWAYS return to MainActivity from recents or after launcher icon click?
My camera app intent:
private void showCamera() {
try {
Intent cameraIntent = new Intent(
android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
path = Utils.getOutputMediaFileUri(getApplicationContext());
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, path);
startActivityForResult(cameraIntent, Constant.CAMERA_REQUEST);
} catch (ActivityNotFoundException ex) {
} catch (Exception ex) {
}
}
The correct way to do this is to add FLAG_ACTIVITY_NO_HISTORY
to the Intent
you use to launch the camera, like this:
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
cameraIntent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
path = Utils.getOutputMediaFileUri(getApplicationContext());
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, path);
startActivityForResult(cameraIntent, Constant.CAMERA_REQUEST);
By adding the NO_HISTORY
flag, you tell Android that you don't want the camera Activity
to leave a historical trace. When the user navigates away from the camera Activity
(ie: by pressing the HOME button, or taking an incoming phone call), the camera Activity
will be immediately finished. When the user then returns to your app (either by selecting it from the list of recent tasks, or by pressing the app's icon on the HOME screen) the camera Activity
will no longer be on top.