Android App自动退出/超时功能
我们开发网络应用程序已经有一段时间了,该应用程序设计为只能通过我们的 Android 应用程序访问。显然,该应用程序本身非常轻量级 - 主要提供创建帐户和登录的功能,以及确保 web 应用程序本身只能通过我们的 Android 应用程序访问 - 但我离题了......
该应用程序非常依赖于 PHP Session变量,这些变量会过期,并且在当前的测试环境中,如果您的会话过期,您无论如何都会被踢到登录屏幕。但在生产中,登录屏幕将位于 Android 应用程序上,完全独立于 WebView。
我现在的想法是让一个服务在后台运行,检查数据库中用户上次活动的时间戳,如果它在某个窗口之外,我们就关闭 webview。但是,如果有什么办法我们可以在 15 分钟(或其他时间)不活动后退出应用程序——那会更好——或者至少更容易……我想……
有没有办法做到这一点——设置有超时自动退出功能吗?或者可以使用 onPause 函数退出应用程序?
We've been working on a webapp for some time now which is designed to be accessed solely through our Android app. Obviously, the App itself is extremely lightweight -- mostly providing functionality for creating accounts and logging in, as well as make sure the webapp itself is only accessible through our Android app - BUT I digress...
The app is pretty dependent on PHP Session variables, which expire, and in the current testing environment, if your session expires you just get kicked out to the login screen anyway. But in production, the login screen will be on the Android app, completely independent of the WebView.
My idea right now is to have a Service run in the background which checks the timestamp we have in the database for a user's last activity, and if it's outside of a certain window, we close the webview. But if there was someway we could just exit the app after 15 minutes (or whatever) of inactivity--that would be preferable--or at least easier... I think...
Is there a way to do this -- set up an auto timeout exit function? Or maybe exit the app with the onPause function?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为什么是
服务
?你不想退出应用程序。您想返回登录屏幕。
检查
WebView
托管活动的onResume()
中的超时状态。如果 Activity 太旧,请为登录屏幕调用startActivity()
,然后调用finish()
关闭WebView
托管 Activity 。Why a
Service
?You do not want to exit the app. You want to go back to the login screen.
Check the timeout status in
onResume()
of theWebView
-hosting activity. If the activity is too old, callstartActivity()
for your login screen, then callfinish()
to close up theWebView
-hosting activity.我知道这会被 Android 开发者视为异端,但这应该可行:
尽管如此,这绝对是最后的手段。
I know this will be considered heresy by Android developers, but this should work:
Still, this would be an absolute last resort.