android - Launching a camera in onCreate causing an intermittent issue -



android - Launching a camera in onCreate causing an intermittent issue -

i trying find best way implement button in mainactivity launches photographic camera activity , returns image activity. returns image activity add together description image... thought thought start single photo view activity when photographic camera button pressed , new activity start photographic camera activity result before doing else; have intermittent issue photographic camera gets stuck in loop.

maybe there improve approach? should launch photographic camera activity result first , pass image intent?

here have now:

@override public boolean onoptionsitemselected(menuitem item) { int id = item.getitemid(); if (id == r.id.action_settings) { homecoming true; }else if ( id == r.id.menu_rules ){ intent rulesintent = new intent(this, rulesactivity.class); startactivity(rulesintent); homecoming true; }else if ( id == r.id.menu_import_photo ){ //pull in image gallery homecoming true; }else if ( id == r.id.menu_item_new_photo ){ startactivity(new intent(mainactivity.this, singlephotoviewactivity.class)); } homecoming super.onoptionsitemselected(item); }

and receiving activity..

public class singlephotoviewactivity extends activity { private static final string log_tag = "simple photographic camera app"; private static int take_picture = 1001; private imageview imageview; private uri imageuri; private bitmap bitmap; private textview textview; private edittext edittext; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_single_photo_view); if ( bitmap == null ) takephoto(); } public void takephoto(){ intent intent = new intent("android.media.action.image_capture"); file photo = new file(environment .getexternalstoragepublicdirectory(environment //this continually overwrite same file //need implement date/ time string //to save file name. .directory_pictures), "pic.jpg"); intent.putextra(mediastore.extra_output, uri.fromfile(photo)); imageuri = uri.fromfile(photo); startactivityforresult(intent, take_picture); } @override public void onactivityresult(int requestcode, int resultcode, intent data) { super.onactivityresult(requestcode, resultcode, data); switch(requestcode) { case 1001: if(resultcode == activity.result_ok) { getcontentresolver().notifychange(imageuri, null); imageview = (imageview )findviewbyid(r.id.ivcameraimageview); contentresolver contentresolver = getcontentresolver(); seek { bitmap = android.provider.mediastore.images.media.getbitmap(contentresolver, imageuri); imageview.setimagebitmap(bitmap); } catch(exception e) { toast.maketext(singlephotoviewactivity.this, "failed load", toast.length_long).show(); log.e(log_tag, e.tostring()); } } } } }

your situation similar happens when action_image_capture intent launched (see e.g. android startcamera gives me null intent , ... destroy global variable?).

the cause scheme may decide destroy caller activity (in case, singlephotoviewactivity), , recreate 1 time again after launched activity (in case, scheme photographic camera activity) returns result.

the ultimate prepare involves implementing onsaveinstancestate(bundle) in calling activity. in specific situation, there shortcut. check intent in oncreate(), , if comes mainactivity, launch camera. else, proceed if going receive onactivityresult() right now.

android android-intent android-activity android-camera

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -