Fix for onActivityResult causing app restart on Motorola devices
My Activity wasn’t returning a result and was causing the entire app to restart, and all I was doing was calling onActivityResult and it wasn’t returning a result. This only happened on Motorola phones that I tested on, specifically the Droid 3 running Android 2.3.4. On Samsung and LG phones there was no such issue. I even left a message with the MotoDevs to ask how I could fix this issue. This will mess up the simplest API calls on any activityForResult call, which will mean PhoneGap calls to camera, videocamera and audio recording won’t work either.
According to this thread on the PhoneGap googlegroups one of the PhoneGap developers stated that this issue is caused by the vendor. Simon replies – “It sounds like you are suffering from the issue that the default intent for taking picture/video does not call onActivityResult properly…This is a vendor bloatware issue and I’m not sure what I can do to fix it.”
I am happy to report that I have found a fix, but I haven’t figured out how to apply this to PhoneGap as of yet. Just add this line to your Intent and it will work:
cameraIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
Here’s the whole block in case this helps
Intent cameraIntent = new Intent(
android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
cameraIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST);
Update: Motorola Devs have not yet been able to reproduce the error even with the test code. It may be an isolated error.
Share Tags
Mensa (Member since 2004)
Hot Skin (Lead Vocalist)
White Widget (Co-Founder)