Android App自动退出/超时功能

发布于 2024-10-14 14:37:35 字数 447 浏览 3 评论 0原文

我们开发网络应用程序已经有一段时间了,该应用程序设计为只能通过我们的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

若相惜即相离 2024-10-21 14:37:35

我现在的想法是在后台运行一个服务,检查数据库中用户上次活动的时间戳,如果它超出了某个窗口,我们就关闭 webview。

为什么是服务

但如果有什么办法我们可以在 15 分钟(或其他时间)不活动后退出应用程序——那会更好——或者至少更容易......我认为......

你不想退出应用程序。您想返回登录屏幕。

检查 WebView 托管活动的 onResume() 中的超时状态。如果 Activity 太旧,请为登录屏幕调用 startActivity(),然后调用 finish() 关闭 WebView 托管 Activity 。

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.

Why a Service?

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...

You do not want to exit the app. You want to go back to the login screen.

Check the timeout status in onResume() of the WebView-hosting activity. If the activity is too old, call startActivity() for your login screen, then call finish() to close up the WebView-hosting activity.

日记撕了你也走了 2024-10-21 14:37:35

我知道这会被 Android 开发者视为异端,但这应该可行:

Activity.moveTaskToBack(true);
Process.killProcess(Process.myPid());

尽管如此,这绝对是最后的手段。

I know this will be considered heresy by Android developers, but this should work:

Activity.moveTaskToBack(true);
Process.killProcess(Process.myPid());

Still, this would be an absolute last resort.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文