'how to save custom view state in android studio

I'm developing an application which has drawing functionality. I want to save my drawing in the room database with the view(whatever users draw). It should be restored when the user clicks on his drawing from their history.

if (stateBundleFromDb!=null){
   super.onCreate(stateBundleFromDb)
   mySavedState = stateBundleFromDb
}else{
   super.onCreate(savedInstanceState)
   mySavedState = savedInstanceState
}

When I click one of the history items I get stateBundleFromDb but when I open the activity directly then I get savedInstanceState.

Is there any possible way to save view state in local storage?

Any help would be appreciated! Thanks.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source