Android: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=Intent
14,135
Solution:
Draw the bitmap during SurfaceChanged, using a flag whether to load image.
Apparently SurfaceView is not ready to be drawn upon at that time, immediately after the MediaStore activity is returning selection
Author by
DKDiveDude
Updated on June 04, 2022Comments
-
DKDiveDude almost 2 years
I am getting an intent delivery error in Logcat, and app stops unexpectedly when I call this;
startActivityForResult(new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI), 1);
or this for that matter;
startActivityForResult(new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI), 1);
and then process it with;
@Override protected void onActivityResult(int requestCode, int resultCode, Intent intent) { super.onActivityResult(requestCode, resultCode, intent); if (resultCode == RESULT_OK) { Uri contentURI = Uri.parse(intent.getDataString()); c = mSurfaceHolder.lockCanvas(); tempCanvas.setBitmap(mDrawing); Bitmap tempBitmap = null; ContentResolver cr = getContentResolver(); try { InputStream in = cr.openInputStream(contentURI); BitmapFactory.Options options = new BitmapFactory.Options(); options.inSampleSize=8; tempBitmap = BitmapFactory.decodeStream(in,null,options); } catch (Exception ee) { tempBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.icon); } tempCanvas.drawBitmap(tempBitmap, 0, 0, null); c.drawBitmap(tempBitmap, 0, 0, null); mSurfaceHolder.unlockCanvasAndPost(c); } }
Errors out with "app has stopped unexpectedly" with logcat showing;
ERROR/AndroidRuntime(24768): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=Intent { act=com.htc.HTCAlbum.action.ITEM_PICKER_FROM_COLLECTIONS dat=content://media/external/images/media/185 }} to activity {com.example.colorbook/com.example.colorbook.Colorbook}: java.lang.NullPointerException Complete logcat as it finished gallery view activity and tried to return intent; 02-03 10:47:22.042: DEBUG/MainActivity(22984): [HTCAlbum][MainActivity][onPause]: Begin 02-03 10:47:22.042: DEBUG/MainActivity(22984): store mCurrentPosition_backup=0 02-03 10:47:22.042: DEBUG/DisplayManager(22984): store mCurrentPosition_backup=0 02-03 10:47:22.092: DEBUG/dalvikvm(22984): GC_EXPLICIT freed 1459 objects / 91880 bytes in 44ms 02-03 10:47:22.102: INFO/AlbumMapper(22984): Create thumbnail for: /mnt/sdcard/workspace/Colorbook/res/drawable/fileload.png 02-03 10:47:22.102: DEBUG/ThumbnailWorker(22984): [stopWorking] Stop working, now join #37, /mnt/sdcard/workspace/Colorbook/res/drawable/fileload.png 02-03 10:47:22.102: DEBUG/AlbumAdapter(22984): set thread priority to normal 02-03 10:47:22.102: DEBUG/AbstractViewGetter(22984): Raise getter prefetcher thread priority to normal. 02-03 10:47:22.102: DEBUG/AbstractViewGetter(22984): Join getter prefetch thread 02-03 10:47:22.102: DEBUG/AbstractViewGetter(22984): Getter prefetch join time: 2 02-03 10:47:22.102: DEBUG/AlbumMapper(22984): cancel current decode operation 02-03 10:47:22.182: DEBUG/AndroidRuntime(24768): Shutting down VM 02-03 10:47:22.182: WARN/dalvikvm(24768): threadid=1: thread exiting with uncaught exception (group=0x400259f8) 02-03 10:47:22.182: ERROR/AndroidRuntime(24768): FATAL EXCEPTION: main 02-03 10:47:22.182: ERROR/AndroidRuntime(24768): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=Intent { act=com.htc.HTCAlbum.action.ITEM_PICKER_FROM_COLLECTIONS dat=content://media/external/images/media/185 }} to activity {com.example.colorbook/com.example.colorbook.Colorbook}: java.lang.NullPointerException 02-03 10:47:22.182: ERROR/AndroidRuntime(24768): at android.app.ActivityThread.deliverResults(ActivityThread.java:3734) 02-03 10:47:22.182: ERROR/AndroidRuntime(24768): at android.app.ActivityThread.handleSendResult(ActivityThread.java:3776) 02-03 10:47:22.182: ERROR/AndroidRuntime(24768): at android.app.ActivityThread.access$2800(ActivityThread.java:135) 02-03 10:47:22.182: ERROR/AndroidRuntime(24768): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2166) 02-03 10:47:22.182: ERROR/AndroidRuntime(24768): at android.os.Handler.dispatchMessage(Handler.java:99) 02-03 10:47:22.182: ERROR/AndroidRuntime(24768): at android.os.Looper.loop(Looper.java:144) 02-03 10:47:22.182: ERROR/AndroidRuntime(24768): at android.app.ActivityThread.main(ActivityThread.java:4937) 02-03 10:47:22.182: ERROR/AndroidRuntime(24768): at java.lang.reflect.Method.invokeNative(Native Method) 02-03 10:47:22.182: ERROR/AndroidRuntime(24768): at java.lang.reflect.Method.invoke(Method.java:521) 02-03 10:47:22.182: ERROR/AndroidRuntime(24768): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 02-03 10:47:22.182: ERROR/AndroidRuntime(24768): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 02-03 10:47:22.182: ERROR/AndroidRuntime(24768): at dalvik.system.NativeStart.main(Native Method) 02-03 10:47:22.182: ERROR/AndroidRuntime(24768): Caused by: java.lang.NullPointerException 02-03 10:47:22.182: ERROR/AndroidRuntime(24768): at com.example.colorbook.Colorbook.loadImageToCanvas(Colorbook.java:524) 02-03 10:47:22.182: ERROR/AndroidRuntime(24768): at com.example.colorbook.Colorbook.onActivityResult(Colorbook.java:231) 02-03 10:47:22.182: ERROR/AndroidRuntime(24768): at android.app.Activity.dispatchActivityResult(Activity.java:3931) 02-03 10:47:22.182: ERROR/AndroidRuntime(24768): at android.app.ActivityThread.deliverResults(ActivityThread.java:3730) 02-03 10:47:22.182: ERROR/AndroidRuntime(24768): ... 11 more 02-03 10:47:22.202: WARN/ActivityManager(97): Force finishing activity com.example.colorbook/.Colorbook 02-03 10:47:22.704: WARN/ActivityManager(97): Activity pause timeout for HistoryRecord{46207010 com.example.colorbook/.Colorbook} 02-03 10:47:22.742: DEBUG/Sensors(97): close_akm, fd=114 02-03 10:47:22.852: DEBUG/MainActivity(22984): [HTCAlbum][MainActivity][onStop]: Begin 02-03 10:47:22.902: DEBUG/dalvikvm(22984): GC_EXPLICIT freed 398 objects / 23264 bytes in 38ms 02-03 10:47:22.902: DEBUG/MainActivity(22984): [HTCAlbum][MainActivity][onDestroy]: Begin 02-03 10:47:22.912: DEBUG/OnlineDataCenter(22984): [HTCAlbum][OnlineDataCenter][unbindContext]: Begin 02-03 10:47:22.912: DEBUG/OnlineDataCenter(22984): [HTCAlbum][OnlineDataCenter][unbindContext]: com.htc.album.MainActivity@46075ec0context size: 0 02-03 10:47:22.912: DEBUG/OnlineDataCenter(22984): [HTCAlbum][OnlineDataCenter][unbindContext]: No more clients. release resources. 02-03 10:47:22.912: DEBUG/OnlineDataCenter(22984): [HTCAlbum][OnlineDataCenter][unbindContext]: End 0 02-03 10:47:22.912: DEBUG/ThumbnailWorker(22984): [stopWorking] Stop working, now join #-1, Decode Complete!! 02-03 10:47:22.912: DEBUG/AlbumAdapter(22984): set thread priority to normal 02-03 10:47:22.912: DEBUG/AlbumMapper(22984): cancel current decode operation 02-03 10:47:22.912: DEBUG/AlbumMapper(22984): cancel current decode operation 02-03 10:47:22.912: DEBUG/ThumbnailWorker(22984): [stopWorking] Stop working, now join #-1, Decode Complete!! 02-03 10:47:22.912: DEBUG/AlbumAdapter(22984): set thread priority to normal 02-03 10:47:22.912: DEBUG/AlbumAdapter(22984): Join worker thread in destroy 02-03 10:47:22.912: DEBUG/AlbumAdapter(22984): Join time: 0 02-03 10:47:22.922: INFO/MainActivity(22984): mWorker finishes jobs at onDestroy(). 02-03 10:47:22.932: DEBUG/CollectionsActivity(22984): [HTCAlbum][CollectionsActivity][onDestroy]: Begin 02-03 10:47:22.932: DEBUG/AlbColAdap(22984): [HTCAlbum][AlbumCollectionsAdapter][onDestroy]: Begin 02-03 10:47:22.942: INFO/BatteryStatsImpl(97): notePhoneSignalStrengthLocked: 2->3 02-03 10:47:22.952: DEBUG/AlbColAdap(22984): [HTCAlbum][AlbumCollectionsAdapter][onDestroy]: End
Line 524 is this; c.drawBitmap(tempBitmap, 0, 0, null);