Android window leak


This issue appear when trying to leave Activity but Dialog still hanging there. Dialog should be closed before leaving Activity.

What a cases that lead to android window leak? Simple, we show Dialog to choose take picture from Camera or Gallery.
If we choose Camera, then it will redirect to Camera MEDIA activity.

1
2
3
4
Uri outputFileUri = Uri.fromFile(newfile);
Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
startActivityForResult(cameraIntent, TAKE_PHOTO_CODE);

This will lead to window leak. Remember to close everything by :


Uri outputFileUri = Uri.fromFile(newfile);
Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
startActivityForResult(cameraIntent, TAKE_PHOTO_CODE);
finish();


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.