How to architect my android app around a 20 minute http session - android

I have an android app that I'm building and it's based on a web app that lets users login and reserve a book (think library). Because you are able to reserve books it needs to have a valid session (cookie to be exact)
Here is my issue - how can I work with multitasking when I have this 20 minute constraint?
Do I keep a timer running the entire time the app is up (in the Application global object) -then on resume verify this timer is under the 20 min window and if so assume cookie is good - else ask them to login again.
Or do I blow away the activities loaded (in my app) on resume and start the app over each time the user clicks the icon from the home screen
Or something else? I simply avoided this in my iPhone version because I don't support multitasking currently (maybe I will if the android solution fits)
Thank you in advance!

Normally people handle this problem by assuming any cookie they have is valid and letting the server tell them if they need to login again. The client should have very little (read: none, if possible) intelligence about this aspect which they cannot control.

You have several options, and which one's the best will depend on the app specifics
You can set up a timer to log out after 20 mins, either as part of your Application or as a part of your Activity (although in the latter approach, it will be lost if the activity is restarted).
Can set an Alarm to fire an Intent to show the login screen after 20 min (if you want to force a re-log in) or to set a flag LOGGED_IN=false if not.
You can set a long field in your Application object and query it during onDraw(), or while fetching a new page, or whenever you deem fit: if it's past the 20 min point, logout.
If the app will be fetching the book from a server one page at a time or similar, then I would add a time token to the POST request and let the server decide whether to return the page or to send a 401 error. You would then handle the error by showing the log in screen and reposting if log in is successful

Related

How to detect if android cordova app is currently running on any device?

The way I've currently set it up,
Each device makes an API call to my server with a unique ID it generates on first launch as POST data.
The API call renews the timestamp of that ID.
The devices make this call every 20 minutes. Hence every 20 minutes, they update the server for with the current time as way of indicating when last they were active on the device.
Then to view the active devices, I've got a web page, which shows me how many devices have had the app running within the last 21 minutes.
But I feel this is a bit primitive, there has to be a more efficient way, even for a hybrid cordova app. I don't think Whatsapp literally checks the network state of devices every millisecond.
If you know any cordova plugin that can help me acheive this, I would be more than grateful that you shared.

Using Android Tasker to override app settings

BACKGROUND:I'm in the process of writing a tasker application that tracks usage of other apps--it keeps track of the time that a reading app is open, for example.
In order to make sure that I'm actually reading and not just leaving the reading app open, I want to make the display timeout 30 seconds long.
ISSUE: The reading app locks the display so it never times out. How can I override the reading app settings to make my 30 second timeout take precedence?
I can't find anything out online because everyone is trying to do the opposite. However, everyone else's Tasker timeout seems to avoid conflicts naturally, so I'm not sure why mine is having issues.
Pseudo code:
Event: Reading app is active AND display is on
Start time = current time
Timeout save = system timeout
Display->display timeout->30 seconds
Event: Reading app closes OR display is off
Total time += current time - start time
Display->display timeout->Timeout save
have you tried with Secure Settings plugin?
it does have better than Tasker control over some of the OS parameters
After extensive research, I have found that there is no way to override the setting. (At least not for the beginners like me)
Google briefly made it possible to override app permissions in Android 4.3, but soon took that privilege away in a subsequent update. Pity.
A cheap and dirty workaround that I came up with is to have a small dialog in a corner with a timer that counts down for your screen timeout. In the last 10 seconds, a button becomes visible which resets the timer and hides the button, or else the display is shut off. (This works for the purposes of MY app -- My intention was to make sure the user was interacting with a third-party reading app, and not just turning it on and walking away, as my app counts the amount of time the reading app is open and the display is on).
#Tomaski - Unfortunately, the Secure Settings plugin doesn't have this power, although you are correct that its capabilities are greater than vanilla Tasker's.

Idle period in Worklight 6.2 Hybrid app

How are application idle settings configured for Worklight 6.2 Hybrid applications?
We are developing a hybrid app for Android 4.1.x with JQuery and would like to return the user to the login page after a period of inactivity...
Is there any in built capability in the framework we should be looking to make use of for this?
There is no built-in idle functionality. You will need to implement a custom one.
One way to achieve this would be to base your custom implementation on counting against the Worklight Server session timeout.
The session timeout is defined in your-project\server\conf\worklight.properties.
What you could do is:
Upon a successful WL.Client.connect(), you will start counting for the same amount as set for the session timeout
For every server action (adapter request...), reset the counting
If the counting expired (or reaches, say, 5-10 seconds before), logout from the realm and display the login form
I don't think it would be good to count for "general" idle time in the app, since you'll need to account for both the session timeout And whichever "activity" timeout you will set, which will have to be Lower than the session timeout. its just more scenarios to take care of...
Edit: actually I have another idea - use the API for heartbeat in Worklight to keep the connection to the server active, and count for whichever activity timeout you would like for the app... If it expires, logout from the realm and display the login form.
You can also do it without pinging the server, with Jquery by attaching the mouse and key listeners to document or body.
Something like this code: (not tested)
var idleTime = 30*1000; //30 seconds
var idleTimer = null;
$(document.body).bind('mousemove,keydown,click',function(){
clearTimeout(idleTimer);
idleTimer = setTimeout(isIdle,idleTime);
});
function isIdle(){
clearTimeout(idleTimer);
//logout and go to login form
}
Another option which maybe a better UX (depending on your specific needs) is to capture the screen turn-off/turn-on natively on device.

Android How to get last user response time

I want to know if the user is away for some amount of time. (and then do something according to it.) I cannot depent on screen sleep because user may have disabled it or its value may be greater than timeout of my application.
is there any information like (last user response time ) in android operation system ? and how can i get it?
last user response time = the last interraction time between the user and the phone.
p.s.:i am targetting android 1.6
No, there is no way to tell when was the last time the user interacted with your application in the SDK. You'll have to do something by yourself.
High level explanation of a simple solution:
Assuming you use some base activity inherited by all activities, you can log the current time in your BaseActivity.onPause method. Save it in the app preferences or in a database. When your initial activity starts (onResume) read the same value and compare it the current time.
You can also use Activity.onUserInteraction but saving to preferences/database everytime this is called will considerably slow down your app / feel less responsive!

Android session starts at same time

I am working with one game which is basically a location based game. The duration of game is 5 mins. Everything is working fine. But the problem is on one device game is starting before the game is started on the other device.
Suppose User A has sent request, user b has accepted the request. then only game screen should appear. But in my case its not happening.
Can anybody help me to give me the logic to start the game between two devices at the same time without a second delay. I am using web service for sending the game requests.
Thanks
Just a thought:
You might use some sort of Mutex on the server side that tries to determine if both clients are ready.
This is assuming the game is run on a server as you described, and not peer to peer.
Hope this helps!
Maybe user B starts when the he accepts but user A hasn't actually received the response yet...or something in that scenario.
How about when user B accepts, take the time (server time to ensure same time) and start around X (10 or 15) seconds after? then send that time (time, not duration) to user A as well. In this case, both user A and user B will just be waiting for the appointed time and then start at the same time? Just an idea, implementation is all up to you :)

Categories

Resources