0

I would like to create an app where a user enter login details in a form to send to my server. Then once all details are correct, a session is created and user is able to view content on my server (say a page that can only be viewed if you logged in successfully), but once the user turns off Wifi or exits the app, the session is broken and user has to login again. Any ideas on how to accomplish this?

Say for example I have a PHP form implementing session based login system, how would my app connect to this?

user1397215
  • 321
  • 1
  • 6
  • 18

1 Answers1

0

use SharedPreferences for storing boolean flag when user properly log in (or logpass or whatever you want). clear/remove this data in onDestroy method of Activity or when you get connection error (exception), which often means no connection at all or maybe some problems with server (e.g. can't parse response)

snachmsm
  • 17,866
  • 3
  • 32
  • 74
  • how often is the connection checked? does it do some sort of polling checking for a connection every x seconds or so? – user1397215 Jan 04 '15 at 22:43
  • Wi-Fi is scanned periodically, but there are also existing some "listeners" called `BroadcastReceiver`'s, more about them in terms of using them for checking Internet connection [HERE](http://stackoverflow.com/questions/15698790/broadcast-receiver-for-checking-internet-connection-in-android-app) – snachmsm Jan 05 '15 at 21:55
  • I am having problems implementing the BroadcastReceiver. At the moment I have a login form in a fragment and a login button. Once this button is pressed login details are verified and a webview is made visible (in the same fragment). I was wondering how could I implement a timeout, say once wifi connection is lost, this webview should shut down and the fragment is reloaded (since the webview and the login form are in the same fragment) prompting the user to login again. – user1397215 Jan 22 '15 at 04:16
  • Should I put the webview in a different fragment and initialise and register the broadcast receiver there? App keeps crashing when turning off and then turning on the wifi while having logged in. – user1397215 Jan 22 '15 at 04:18
  • probably separated Fragment for `WebView` isn't necessary, but itss hard to say without log – snachmsm Jan 22 '15 at 08:42