android - Difference between oncreate and onRestoreInstanceState method in activity -
Friends I got stuck in a problem with these two methods: -
When I change orientation Set text after tooling the tool and the text with the bundle, it does not work. But this code is working on the Honeststore Instant Method.
Please take a look at my code: -
Expands the LifeCycleActivity Activity of Public Sector OnClickListener is called {/ ** when activity has been created first / Edit text user; Override public null on @reate (bundle saved instainstate) {super.naught (savedinstenstate); SetContentView (R.layout.main); User = (EditText) findViewById (R.id.et_user); If (Saved InstanceState! = Blank) {String S = Saved InstantState.Gate ("Key") ToString (); User = (EditText) findViewById (R.id.et_user); User.setText (. SavedInstanceState.get ("key") toString ()); Toast. Make Text (this, S, Toast. LNGHORART). Show (); } Toast. Maketext (this, "On Crate", Toast. LNGHHARART). Show (); Button B = (button) Find VVBIID (R.B. button 1); B.setOnClickListener (this); } @ Override Protected Zero to Savings InstantState (Bundle Outstate) {super.onSaveInstanceState (outstate); Toast. Maketext (this, "OnSwinstanceState", Toast. LNGHHRART). Show (); OutState.putString ("key", "lamp"); } @ Override Protected Zero to Restore InstantState (InstanceState saved from bundle) {Super. Restore InstantState (Saved Instantstate); // String s = Saved InstantState.Gate ("Key"). ToString (); //user.setText(s); Toast. Maketext (this, "Onestor Instestat", Toast. LNGHHRART). Show (); } @ Override protected void onStart () {// TODO auto-generated method stub super.onStart (); Toast. Maketext (this, "Onstart", Toast. LNGHORART). Show (); } @ Override Protected Zero Resum () {// TODO Auto-Generated Method Stub Super.onResume (); Toast. Make text (this, "On Résumé", Toast. LNGHIORART). Show (); } @ Override Protected Zero at POS () {// TODO Auto generated method Stub Super.Pano (); Toast. Make Text (this, "On Pause", Toast. LNNGHHORART). Show (); } @ Override protected ontop () {// Todo auto generated method stub super. Ontop; Toast. Make Text (this, "Ontop", Toast. LNGHHARART). Show (); } @Override Safe void onDestroy () {// TODO auto generated method stub super.onDestroy (); Toast. Make Text (this, "On Destroy", Toast. LNNHHARART) Show (); } @ Override Secure Zero Restart () {// TODO Auto-Generated Method Stub Super.OnSTST (); Toast. Maketext (this, "OnerStart", Toast.LnGHIORART). Show (); } @ Override Public Zero (see ARG0) {// TODO auto-generated method stub launches (new intact (this, second activitie.class)); } }
When I get the value from the bundle and set the text in the address text, it does not work. But the same code works on the OnRestoreInstanceState () method.
According to me, this bundle class can get there object as well as should work strictly. Please help me solve this problem ..
edit text and Most other scenes have their own ways to save / restore their own data. So normally it is not necessary to save / restore to your code. You can see it on line at 3546 (Remember that the text shows with the text text):
if (SStext! = Null) {set text ( SStext); } So you can not set it to onCreate and you can do it onRestoreInstanceState This is because during your activity < Code> super .onRestoreInstanceState (Saved InstanceState) calls activity call EditText.onRestoreInstanceState and editing text restores itself in the previous value. You can view it on-line 940
Bundle on the Restore InstantState (Bundle Saved Instantstate) {if (mWindow! = Null) {Bundle WindowState = Saved InstantState.Det Bundle (WINDOW_HIERARCHY_TAG); If (windowstate! = Null) {mWindow.restoreHierarchyState (windowState); }}} Hope this helps.
Comments
Post a Comment