Reputation: 427
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?
Upvotes: 8
Views: 6726
Reputation: 1006744
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.
Upvotes: 7
Reputation: 6126
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.
Upvotes: -1