android - My app got a confusing errors. Sometime it work correctly and sometime not -



There are 2 actions in this app: main activity and setting activation (for the purpose of sending value) ... main Activity:

  string set = "1"; Crate on Public Zero (Bundle Instant) {Super. Contant (immediate); SetContentView (R.layout.camera);  

... When my app is running, I change the value of the set: set = "2" by setting the activation, and it's true in main activity Then, I press the Home button, and again start this app, it works with set = "1" ; layout in camera.xml; And when I press the back button: After making slight changes to the screen, it works with the set = "2" layout camera.xml.

Why are 2 layouts? Press it again after the press home button and press the back button to get the exact value of set in that time, why do I have to buy the InstantState (bundle) Quick) but it's still the same.

Have you tried to see this answer before

when you home If you press the button and you return to your application, it can be restarted and therefore the set variable returns to its original value. To save your variable, you must write the remaining public spaces (bundle saved instancestate) at @SaveInstanceState {super.onSaveInstanceState (savedInstanceState); // Save changes in UI position in Saved InstantState // This bundle will be passed to turn on if process // is executed and restarted. SavedInstanceState.putString ("Set", set); }

Then you can recover the values ​​in this way:

  Override public null at @RestoreStateInstanceState (bundled saved instainstate) {super .onRestoreInstanceState (SavedInstanceState); // Restore UI status from Saved InstanceStat // This bundle is also passed on for crate. String Maestring = Reserved Stainstate.GetString ("Set"); }  

Besides, why are you using string to contain integer values?

Hope for this help


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -