I’m building an android app which has a login and logout option. How do I make the app go back to login screen if the user has logged in and not used it(or kept idle) for some time(say 10min)? Also, how do I check for multiple logins? Please note that my app uses an external database(mysql). I did this using php code. Also, how do I check for multiple logins(I’ve multiple users) from mysql and allow each user to log in?
This is my code for authentication:
try
{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://10.0.2.2/user_validate.php");
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
InputStream inputStream = entity.getContent();
byte[] data = new byte[256];
buffer = new StringBuffer();
int len = 0;
while (-1 != (len = inputStream.read(data)) )
{
buffer.append(new String(data, 0, len));
}
inputStream.close();
}
catch (Exception e)
{
Toast.makeText(Login.this, "error"+e.toString(), Toast.LENGTH_LONG).show();
}
if(buffer.charAt(0)=='Y')
{
Intent intent = new Intent(getApplicationContext(),
Home.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
finish();
startActivity(intent);
}
In the app or on the server you want to store the timestamp of the last successfully completed user action (that requires login credentials).
Then test against that timestamp to see if the current request is more or less than the 10 min threshold. If its longer than 10 mins after the last successful timestamp then you need to get the user to log in again.