android - ImageView crop image disappear when change orientation -


i have activity take picture, crop image , show cropped image. here code.

public class mainactivity extends activity {     private static final int takepicture = 1;     imageview imgview;       @override     public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);         imgview = (imageview) findviewbyid(r.id.imageview1);         button buttoncamera = (button) findviewbyid(r.id.btn_take_camera);         buttoncamera.setonclicklistener(new view.onclicklistener() {             public void onclick(view v) {                 // call android default camera                 intent intent = new intent(mediastore.action_image_capture);                 intent.putextra(mediastore.extra_output,mediastore.images.media.external_content_uri.tostring());                 // ******** code crop image                 intent.putextra("crop", "true");                 intent.putextra("aspectx", 0);                 intent.putextra("aspecty", 0);                 intent.putextra("outputx", 200);                 intent.putextra("outputy", 150);                 try {                     intent.putextra("return-data", true);                     startactivityforresult(intent, takepicture);                 } catch (activitynotfoundexception e) {                     // nothing                 }             }         });     }     protected void onactivityresult(int requestcode, int resultcode, intent data) {               bundle extras = data.getextras();             if (extras != null) {                 bitmap photo = extras.getparcelable("data");                 imgview.setimagebitmap(photo);             }     }  } 

when change orientation portrait landscape, image set in bitmap disappear. there way save current state of image if orientation changed landscape portrait or vice versa.?

you don't have method saves current state of app. use onsaveinstancestate in order save. can find here activity , saving values: http://developer.android.com/reference/android/app/activity.html

kind regards


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -