如何保存onClickListener的状态?
我有一个实现多个 onClickListener 的程序。因此,随着用户点击按钮的进展。是否有办法保存用户在离开应用程序或被销毁之前使用的 onClick 侦听器?
I have a program that implements several onClickListeners. So as the user progresses through the button clicks. Is there anyway to save which onClick listener the user was on before they left the application or is was destroyed?
使用共享首选项来实现这一点。每当您单击任何按钮时,都会存储按钮名称及其值。
示例
和 oncreate() 中始终使用以下代码获取按钮的状态
示例示例
取决于您可以设置按钮状态的值
Use sharedpreference to achieve this. store the button name and its value whenever you click on any button.
example
and in oncreate() always get the state of button using the following code
Sample example
depending on the value you can set the state of button