Friday, 15 February 2013

android - Activity is destroyed after coming back from camera app -


I have an activity with the dialog when I click on the default Camera App Launch ImageView and when I make a picture and Clicking on the tick icon (at least this is a tick icon on my phone), the previous activity is rebuilt, destroyed, and rebuilt. This is about 1 in 10 times.

It happens

  1 Intent Camera 2. Opens onPause () 3. onSaveInstanceState 4. onStop () 5. OnDestroy () 6. Camera app, opens the picture is taken and I click the tick 7. onStart :() 8. onRestoreInstanceState 9. onResume runs (runs) 10 onPause () 11. onSaveInstanceState 12. onStop () 13. OnDestroy () 14. onStart :() 15. onRestoreInstanceState  

I data I is destroyed when taken even though (Step save need onSaveInstanceState 3) and OnRestoreInstanceState (step 8), the activity is lost (I use a flag, so I saved data Want is to decide when the activity is created for the second time) that the flag be null.

If something matters, then there is some code:

Intent

  btn_camera.setOnClickListener (New View. OnClickListener () {@Override public void onClick (View arg0) {which_dialog = "full"; complete_dialog.dismiss (); imageFileForCamera_ = getTemporaryDirectory (); effect IntentPicture = new intent (MediaStore.ACTION_IMAGE_CAPTURE); if (imageFileForCamera_! = null) {IntentPicture.putExtra (MediaStore Extra_UTPUT, Yuri.framefile (imageFileForCamera_));} startActivityForResult (Intent Picture, PICK_FROM_CAMERA_COMPLETE_KITKAT);  

onActivityResult:

  Case PICK_FROM_CAMERA_COMPLETE_KITKAT: selectedImageUri = Uri.fromFile (imageF ileForCamera_); complete_dialog.show (); (... and code ...)  

onSaveInstanceState

  @ override Protected Zero OS AveInstanceState (Bundle Outstate) {super.onSaveInstanceState (outstate); if (j_addoog! = Null & amp; Jo_milog Lang () & gt; 1) {outState.putString ("jo_iptOug", which is_command); OutState.putSerializable (INSTANCE_STATE_IMAGE_FILE_FOR_CAMERA, imageFileForCamera_); } Else {Log.i ("onSaveInstanceState what_dialog", "which_dialog is zero"); }}  

onRestoreInstanceState

  @Override zero onRestoreInstanceState (bundled savedInstanceState) {super.onRestoreInstanceState (savedInstanceState) is protected; if (! savedInstanceState = null) {if (savedInstanceState.containsKey ( "which_dialog")) {if (savedInstanceState.getString ( "which_dialog") equal to ( "full").) {complete_dialog = new CompleteDialog (ActivitykThis); ImageFileForCamera_ = (File) SavedStainState. Getable for Gate (INSTANCE_STATE_IMAGE_FILE_FOR_CAMERA); }}} {Log (i.e. "Onorstor Instant", "Saved InstantStat is empty"); }}  

After

You are saving which_dialog Code> onSaveInstanceState () . You are not restoring onRestoreInstanceState () in the which_dialog to set your onRestoreInstanceState () to set which_dialog The price is based on the saved in onSaveInstanceState () .


No comments:

Post a Comment