Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android App auto-exit/timeout functionality

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?

like image 591
user446882 Avatar asked Jan 26 '11 21:01

user446882


People also ask

How do you close out apps on an Android?

Close one app: Swipe up from the bottom, hold, then let go. Swipe up on the app. Close all apps: Swipe up from the bottom, hold, then let go. Swipe from left to right.

How do you exit out of an app?

You can call System. exit(); to get out of all the acivities.

How do I close a program in Android programmatically?

use 'System. exit(0);' when you really want to exit the app.

What code is executed when an Android application is launched?

main. So although the call stack of an Android application start at ZygoteInit. main, the code executed in ZygoteInit. main begins after the call to runSelectLoop instead of the beginning of ZygoteInit.


1 Answers

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.

like image 112
CommonsWare Avatar answered Nov 15 '22 00:11

CommonsWare