Closed ssyijiu closed 7 years ago
How about to use required
option?
@AutoBundleField
required to be contain in Bundle as default.
So set false to annotation.
Here is sample code...
public class LoginActivity extends AppCompatActivity {
@AutoBundleField(required = false) String status = "Default";
@AutoBundleField String name, password;
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (savedInstanceState == null) {
AutoBundle.bind(this, getIntent());// status == "Default"
} else {
AutoBundle.bind(this, savedInstanceState);// status restored from state.
}
}
@Override protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
AutoBundle.pack(this, outState);
}
}
Thanks for your answer . It solved my problem perfectly.
I use the follow code in Activity#onCreate
and
@AutoBundleField String status,name,password;
thename
andpassword
I get from a Intent, thestatus
I only want to Save The State, when I first open the Acticity from other activity,AutoBundle.bind(this, getIntent())
execute , and I don't put thestatus
in intent, finally there is a IllegalStateException .I find the cause: