java - Trouble with displaying captured pic in Imageview (Android studio) -


i using android studio , had app working press button open samsung galaxies camera , take pic. can save pic , displays in imageview within application. since today picture not display in imageview. still saves dissappears after take picture. if hold phone sideway image shows @ first once hold device straight image vanish. not understand , new android studios , coding in general. if appreciated :) ? when image dissappears, error appears in logs: 32351-32351/com.andyexample.myapplication e/viewrootimpl﹕ senduseractionevent() mview == null.

code main activity:

public class mainmenu extends actionbaractivity {

static final int request_image_capture = 1; imageview imageview;   //drawable dirty; //bitmap bitmapimage;    @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main_menu);       imageview = (imageview) findviewbyid(r.id.imageview);     button opencamera = (button) findviewbyid(r.id.opencamera);     button buttonfilter = (button) findviewbyid(r.id.buttonfilter);      }    //launching camera  public void launchcamera(view view){     intent intent = new intent(mediastore.action_image_capture);      //take picture taken along result activity     startactivityforresult(intent, request_image_capture);      }  //if want save image  @override protected void onactivityresult(int requestcode, int resultcode, intent data) {     if(requestcode == request_image_capture && resultcode == result_ok){          //get photo         bundle extras = data.getextras();         bitmap  photo = (bitmap) extras.get("data");         imageview.setimagebitmap(photo);        } } 

as @squonk described, bitmap lost when rotate device, activity destroyed , recreated (so can create it's layout in new orientation).

so, need save bitmap activity destroyed, , read when activity recreated.

you can follows:

  // save activity's instance state gets destroyed   @override   public void onsaveinstancestate(bundle outstate) {     super.onsaveinstancestate(outstate);     outstate.putparcelable("bitmap", bitmap);   }   // restore saved instance state  @override   public void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main_menu);     imageview = (imageview) findviewbyid(r.id.imageview);      if (savedinstancestate != null) {        bitmap = savedinstancestate.getparcelable("bitmap");     }      if(bitmap != null) {       imageview.setimagebitmap(photo);     }  } 

note have make 'bitmap' instance member of activity, instead of local variable.


Comments

Popular posts from this blog

How to group boxplot outliers in gnuplot -

cakephp - simple blog with croogo -

bash - Performing variable substitution in a string -