Reputation: 205
I have a problem with adding values in savedInstanceState
in Android. I tried to find solution on the internet, but I cannot seem to find a solution. Maybe some of you might know where the problem is. I need to put HashMap> to savedInstanceState
, and retrieve that onCreate method. Has anyone encountered and solved this problem?
Thank you for your time.
Upvotes: 4
Views: 2293
Reputation: 1834
Try :
private HashMap<String, String> savedInstanceMap = new HashMap<>();
@Override
public void onSaveInstanceState(@NonNull Bundle outState) {
savedInstanceMap.put("selectedFuel_type_Id", selectedFuel_type_Id);
outState.putSerializable("savedBundle", savedInstanceMap);
super.onSaveInstanceState(outState);
}
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (savedInstanceState != null) {
savedInstanceMap = (HashMap<String, String>) savedInstanceState.getSerializable("savedBundle");
selectedFuel_type_Id = savedInstanceMap.get("selectedFuel_type_Id");
}
Upvotes: 0
Reputation: 157457
you can use putSerializable. E.g.
savedInstanceState.putSerializable("KEY", hashMapInstance);
Upvotes: 9