In my activity I have a custom view which I add on top of the RootView. Inside the custom view I have two Radiobuttons. When I remove the activity from the RootView the state of the radio buttons is gone. How can I save the state of the radiobuttons without the activity lifecycle?
Here is my code for better understanding the question:
class MyCustomView : View
var myCustomView: View = View.inflate(context, R.layout.custom_view, null)
val closeButton by lazy {
myCustomView.findViewById(R.id.btn_close) as AppCompatImageView
}
init {
val rootView = (context as Activity).window.decorView.findViewById(android.R.id.content) as ViewGroup
rootView.addView(myCustomView)
setCloseButtonClickListener(closeButton, rootView)
}
fun setCloseButtonClickListener(closeButton: AppCompatImageView,
rootView: ViewGroup) {
closeButton.setOnClickListener { onCloseButtonClick(rootView) }
fun onCloseButtonClick(rootView: ViewGroup) {
rootView.removeView(myCustomView)
}
When the user click the close button, the view will removed / closed from the root view