Home > Mobile >  Help have a look at why can't get savedInstanceState value
Help have a look at why can't get savedInstanceState value

Time:04-08

 
The class MainActivity: AppCompatActivity () {
Private val tag="MainActivity"
Override fun onSaveInstanceState (outState: Bundle) {
The d (tag, "onSaveInstanceState ()...
")Super. OnSaveInstanceState (outState)//temporarily saved data
STR val temdata="https://bbs.csdn.net/topics/something"
OutState. PutString (" data1 ", temdata)
Val temdata2=99.99
OutState. PutDouble (" data2 ", temdata2)
Val temdata3=false
OutState. PutBoolean (" data3, "temdata3)
}

Override fun onCreate (savedInstanceState: Bundle? {
Super. OnCreate (savedInstanceState)
The d (tag, "onCreate..
")Val binding=ActivityMainBinding. Inflate (layoutInflater)
The setContentView (binding. Root)
If (savedInstanceState!=null) {
The d (tag, "running...
")The d (tag, "STR: ${savedInstanceState. Get string (" data1")} ")
The d (tag, "double: ${savedInstanceState. GetDouble (" data2")} ")
The d (tag, "Boolean: ${savedInstanceState. GetBoolean (" data3")} ")
} the else
The d (tag, "savedInstanceState is null...
")Binding. BtnShowNormal. SetOnClickListener {
Val intent=intent (this, NormalActivity: : class. Java)
StartActivity (intent)
}
Binding. BtnShowDialog. SetOnClickListener {
Val intent=intent (this, DialogActivity: : class. Java)
StartActivity (intent)
}
}//end oncreate
  • Related