Android 按下后退按钮时强制刷新
我在 Android 上使用 PhoneGap,当 Android 后退按钮将应用程序带回到某个页面时,我需要我的应用程序强制刷新。知道我该怎么做吗?
谢谢!
I'm using PhoneGap with Android, and I need my app to force a refresh when the Android back button takes the app back to a certain page. Any idea how I can do this?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以重写“onBackPressed”方法。
显示下面的示例代码。
如果您想在按下后退键时控制页面导航, ,
在'onBackPressed'方法中调用javascript函数。
当按下回键时,上面的代码将调用名为“method_name”的 javasctipt 函数。
您可以在 javascript 函数中编写“页面控制代码”。
you can override 'onBackPressed' method.
show below example codes.
if you wanna control page navigation when back key pressed,
call javascript function in 'onBackPressed' method.
Above code will call function javasctipt named 'method_name' when back pressed.
and you can write 'page-control code' in javascript function.
您可以使用
startActivityForResult(Intent Intent, int requestCode)
方法启动新活动。如果在该新活动中按下后退按钮,它将向前一个活动发送取消的结果,而前一个活动又必须处理该结果。因此,在第一个活动中,使用以下方法捕获结果:从这里开始,您所需要做的就是创建一个实现所需刷新的方法,并从上面的代码中调用它。
You can launch a new activity using the
startActivityForResult(Intent intent, int requestCode)
method. If the back button is pressed within that new activity, it will send a cancelled result to the previous activity, which in turn must handle that result. Therefore, in the first activity, catch that result using:From here, all you need do is create a method that implements the refresh that you desire, and call it from within the above code.