简体   繁体   English

单击电话后退按钮时重置活动

[英]Reset Activity when phones back button is clicked

Is it possible to reset a activity to its normal state when a user clicks the back button from the previous page. 当用户单击上一页的后退按钮时,是否可以将活动重置为正常状态。

Use Case: On my main activity I have checkboxes and the user goes to the next activity using intent. 用例:在我的主要活动中,我有复选框,并且用户使用意图转到下一个活动。 That activity has a "Back to Main Page" button, but when the user just clicks the back button on the phone the checkboxes are already checked from the last time the user was on the page. 该活动具有“返回主页”按钮,但是当用户仅单击电话上的“后退”按钮时,从上一次用户在页面上开始,便已选中该复选框。

If you want to reset only when returning from that activity then use startActivityForResult() and override onActivityResult . 如果仅在从该活动返回时才想重置,请使用startActivityForResult()并覆盖onActivityResult

If you want to reset everytime then reset in onResume() 如果您想每次重置,请在onResume()重置

将设置复选框默认状态的代码从onCreate()移到onResume()方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM