android - unable to resume activity after random selection between pick from gallery and pick from camera -
i unable find root cause of problem unable resume activity. doing wrong app goes crash once random selection between pick gallery , pick camera :(
edit: full logcat:
04-05 12:30:07.479: w/iinputconnectionwrapper(17228): showstatusicon on inactive inputconnection 04-05 12:30:17.109: i/rotateimage(17228): exif orientation: 6 04-05 12:30:17.109: i/rotateimage(17228): rotate value: 90 04-05 12:30:20.139: e/swiss insignia(17228): width=1920 04-05 12:30:20.139: e/swiss insignia(17228): height=2560 04-05 12:30:21.609: i/system.out(17228): str1=l@** 04-05 12:30:31.229: i/rotateimage(17228): exif orientation: 6 04-05 12:30:31.229: i/rotateimage(17228): rotate value: 90 04-05 12:30:33.949: e/swiss insignia(17228): width=1920 04-05 12:30:33.949: e/swiss insignia(17228): height=2560 04-05 12:30:35.089: i/system.out(17228): str2=l@** 04-05 12:30:37.909: w/iinputconnectionwrapper(17228): showstatusicon on inactive inputconnection 04-05 12:30:45.829: i/swiss insignia(17456): trying load opencv library 04-05 12:30:45.889: d/skia_font(17456): load_system_fonts(), name = roboto, style = 0, uniqueid = 1 04-05 12:30:45.889: d/skia_font(17456): load_system_fonts(), name = roboto, style = 1, uniqueid = 2 04-05 12:30:45.889: d/skia_font(17456): load_system_fonts(), name = droid serif, style = 0, uniqueid = 3 04-05 12:30:45.889: d/skia_font(17456): load_system_fonts(), name = droid serif, style = 1, uniqueid = 4 04-05 12:30:45.889: d/skia_font(17456): load_system_fonts(), name = droid serif, style = 2, uniqueid = 5 04-05 12:30:45.899: d/skia_font(17456): load_system_fonts(), name = droid serif, style = 3, uniqueid = 6 04-05 12:30:45.899: d/skia_font(17456): load_system_fonts(), name = droid sans mono, style = 0, uniqueid = 7 04-05 12:30:45.909: d/skia_font(17456): load_system_fonts(), name = droid sans arabic, style = 0, uniqueid = 8 04-05 12:30:45.909: d/skia_font(17456): load_system_fonts(), name = droid sans hebrew, style = 0, uniqueid = 9 04-05 12:30:45.909: d/skia_font(17456): load_system_fonts(), name = samsungarmenian, style = 0, uniqueid = 10 04-05 12:30:45.909: d/skia_font(17456): load_system_fonts(), name = samsunggeorgian, style = 0, uniqueid = 11 04-05 12:30:45.909: d/skia_font(17456): load_system_fonts(), name = droid sans thai, style = 0, uniqueid = 12 04-05 12:30:45.909: d/skia_font(17456): load_system_fonts(), name = helvem_telugu, style = 0, uniqueid = 13 04-05 12:30:45.909: d/skia_font(17456): load_system_fonts(), name = droid sans fallback, style = 0, uniqueid = 14 04-05 12:30:45.919: d/skia_font(17456): load_system_fonts(), oldsansuid = 0, newsansuid = 1 04-05 12:30:45.919: d/skia_font(17456): load_system_fonts(), oldsansbolduid = 0, newsansbolduid = 2 04-05 12:30:45.969: w/dalvikvm(17456): threadid=1: thread exiting uncaught exception (group=0x40018578) 04-05 12:30:45.989: e/androidruntime(17456): fatal exception: main 04-05 12:30:45.989: e/androidruntime(17456): java.lang.runtimeexception: unable resume activity {.mainactivity}: java.lang.runtimeexception: failure delivering result resultinfo{who=null, request=1, result=-1, data=null} activity {.mainactivity}: java.lang.nullpointerexception 04-05 12:30:45.989: e/androidruntime(17456): @ android.app.activitythread.performresumeactivity(activitythread.java:2124) 04-05 12:30:45.989: e/androidruntime(17456): @ android.app.activitythread.handleresumeactivity(activitythread.java:2139) 04-05 12:30:45.989: e/androidruntime(17456): @ android.app.activitythread.handlelaunchactivity(activitythread.java:1672) 04-05 12:30:45.989: e/androidruntime(17456): @ android.app.activitythread.access$1500(activitythread.java:117) 04-05 12:30:45.989: e/androidruntime(17456): @ android.app.activitythread$h.handlemessage(activitythread.java:935) 04-05 12:30:45.989: e/androidruntime(17456): @ android.os.handler.dispatchmessage(handler.java:99) 04-05 12:30:45.989: e/androidruntime(17456): @ android.os.looper.loop(looper.java:130) 04-05 12:30:45.989: e/androidruntime(17456): @ android.app.activitythread.main(activitythread.java:3687) 04-05 12:30:45.989: e/androidruntime(17456): @ java.lang.reflect.method.invokenative(native method) 04-05 12:30:45.989: e/androidruntime(17456): @ java.lang.reflect.method.invoke(method.java:507) 04-05 12:30:45.989: e/androidruntime(17456): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:867) 04-05 12:30:45.989: e/androidruntime(17456): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:625) 04-05 12:30:45.989: e/androidruntime(17456): @ dalvik.system.nativestart.main(native method) 04-05 12:30:45.989: e/androidruntime(17456): caused by: java.lang.runtimeexception: failure delivering result resultinfo{who=null, request=1, result=-1, data=null} activity {.mainactivity}: java.lang.nullpointerexception 04-05 12:30:45.989: e/androidruntime(17456): @ android.app.activitythread.deliverresults(activitythread.java:2536) 04-05 12:30:45.989: e/androidruntime(17456): @ android.app.activitythread.performresumeactivity(activitythread.java:2111) 04-05 12:30:45.989: e/androidruntime(17456): ... 12 more 04-05 12:30:45.989: e/androidruntime(17456): caused by: java.lang.nullpointerexception 04-05 12:30:45.989: e/androidruntime(17456): @ .onactivityresult(mainactivity.java:101) 04-05 12:30:45.989: e/androidruntime(17456): @ android.app.activity.dispatchactivityresult(activity.java:3908) 04-05 12:30:45.989: e/androidruntime(17456): @ android.app.activitythread.deliverresults(activitythread.java:2532) 04-05 12:30:45.989: e/androidruntime(17456): ... 13 more
code:
public class mainactivity extends activity { private static final int pick_from_camera = 1; private static final int pick_from_gallery = 2; final string tag = "swiss insignia"; imageview imgview; textview output; button buttoncamera; button buttongallery; file destimage; private baseloadercallback mopencvcallback = new baseloadercallback(this) {@override public void onmanagerconnected(int status) { switch (status) { case loadercallbackinterface.success: { log.i(tag, "opencv loaded successfully"); // create , set view system.loadlibrary("swissinsignia"); log.i(tag, "libswissinsignia.so loaded successfully"); } break; default: { super.onmanagerconnected(status); } break; } } };@override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); log.i(tag, "trying load opencv library"); if (!opencvloader.initasync(opencvloader.opencv_version_2_4_2, this, mopencvcallback)) { log.e(tag, "cannot connect opencv manager"); } setcontentview(r.layout.activity_main); imgview = (imageview) findviewbyid(r.id.imageview1); output = (textview)findviewbyid(r.id.textviewoutput); buttoncamera = (button) findviewbyid(r.id.btn_take_camera); buttongallery = (button) findviewbyid(r.id.btn_select_gallery); buttoncamera.setonclicklistener(new view.onclicklistener() { public void onclick(view v) { intent intent = new intent(android.provider.mediastore.action_image_capture); file dir = new file(environment.getexternalstoragedirectory().getabsolutepath(), "swissinsignia"); if (!dir.isdirectory()) { dir.mkdir(); } destimage = new file(dir, new date().gettime() + ".jpg"); intent.putextra(mediastore.extra_output,uri.fromfile(destimage)); startactivityforresult(intent, pick_from_camera); } }); buttongallery.setonclicklistener(new view.onclicklistener() { public void onclick(view v) { intent photopickerintent = new intent(intent.action_get_content); photopickerintent.settype("image/*"); startactivityforresult(photopickerintent, pick_from_gallery); } }); } protected void onactivityresult(int requestcode, int resultcode, intent data) { if (requestcode == pick_from_camera) { file f = new file(destimage.getabsolutepath()); int rotateimage = getcameraphotoorientation(this, uri.parse(destimage.getabsolutepath()), destimage.getabsolutepath()); bitmap photo= convertbitmaptocorrectorientation( bitmapfactory.decodefile(f.getabsolutepath()), rotateimage); //bitmap photo = bitmapfactory.decodefile(f.getabsolutepath()); log.e(tag, "width="+photo.getwidth()); log.e(tag, "height="+photo.getheight()); mat mrgba=new mat(); org.opencv.android.utils.bitmaptomat(photo,mrgba); string str1=findfeatures(mrgba.getnativeobjaddr()); system.out.println("str1="+str1); imgview.setimagebitmap(photo); output.settext("detected pattern="+str1); } if (requestcode == pick_from_gallery) { uri selectedimage = data.getdata(); string[] filepathcolumn = { mediastore.images.media.data }; cursor cursor = getcontentresolver().query(selectedimage,filepathcolumn, null, null, null); cursor.movetofirst(); int columnindex = cursor.getcolumnindex(filepathcolumn[0]); string picturepath = cursor.getstring(columnindex); cursor.close(); int rotateimage = getcameraphotoorientation(this, selectedimage, picturepath); bitmap photo= convertbitmaptocorrectorientation( bitmapfactory.decodefile(picturepath), rotateimage); log.e(tag, "width="+photo.getwidth()); log.e(tag, "height="+photo.getheight()); mat mrgba=new mat(); org.opencv.android.utils.bitmaptomat(photo,mrgba); string str2=findfeatures(mrgba.getnativeobjaddr()); system.out.println("str2="+str2); bitmap mutablebitmap = photo.copy(bitmap.config.argb_8888, true); imgview.setimagebitmap(mutablebitmap); output.settext("detected pattern="+str2); } } public static bitmap convertbitmaptocorrectorientation(bitmap photo,int rotation) { int width = photo.getwidth(); int height = photo.getheight(); matrix matrix = new matrix(); matrix.prerotate(rotation); return bitmap.createbitmap(photo, 0, 0, width, height, matrix, false); } public int getcameraphotoorientation(context context, uri imageuri, string imagepath) { int rotate = 0; try { context.getcontentresolver().notifychange(imageuri, null); file imagefile = new file(imagepath); exifinterface exif = new exifinterface(imagefile.getabsolutepath()); int orientation = exif.getattributeint(exifinterface.tag_orientation, exifinterface.orientation_normal); switch (orientation) { case exifinterface.orientation_rotate_270: rotate = 270; break; case exifinterface.orientation_rotate_180: rotate = 180; break; case exifinterface.orientation_rotate_90: rotate = 90; break; } log.i("rotateimage", "exif orientation: " + orientation); log.i("rotateimage", "rotate value: " + rotate); } catch (exception e) { e.printstacktrace(); } return rotate; } public static native string findfeatures( long mataddrrgba); }
the problem simple activity restarting when coming camera because camera uses lot of resource work hence destimage null
so use on onsaveinstancestate
save these king of variables , restore them @ oncreate bundle savedinstancestate
or
use
destimage = new file(dir, "sample.jpg");
at oncreate()
, not in onclick()
edit
also check if result ok resultcode==result_ok
protected void onactivityresult(int requestcode, int resultcode, intent data) { if(resultcode== result_ok ) { if (requestcode == pick_from_camera) { file f = new file(destimage.getabsolutepath()); int rotateimage = getcameraphotoorientation(this, uri.parse(destimage.getabsolutepath()), destimage.getabsolutepath()); bitmap photo= convertbitmaptocorrectorientation( bitmapfactory.decodefile(f.getabsolutepath()), rotateimage); //bitmap photo = bitmapfactory.decodefile(f.getabsolutepath()); log.e(tag, "width="+photo.getwidth()); log.e(tag, "height="+photo.getheight()); imgview.setimagebitmap(photo); output.settext("detected pattern="); } if (requestcode == pick_from_gallery) { uri selectedimage = data.getdata(); string[] filepathcolumn = { mediastore.images.media.data }; cursor cursor = getcontentresolver().query(selectedimage,filepathcolumn, null, null, null); cursor.movetofirst(); int columnindex = cursor.getcolumnindex(filepathcolumn[0]); string picturepath = cursor.getstring(columnindex); cursor.close(); int rotateimage = getcameraphotoorientation(this, selectedimage, picturepath); bitmap photo= convertbitmaptocorrectorientation( bitmapfactory.decodefile(picturepath), rotateimage); log.e(tag, "width="+photo.getwidth()); log.e(tag, "height="+photo.getheight()); bitmap mutablebitmap = photo.copy(bitmap.config.argb_8888, true); imgview.setimagebitmap(mutablebitmap); output.settext("detected pattern="); } } }
Comments
Post a Comment