ISSUE AT HAND:
The app itself will perform an auto session timeout logout when the app is pushed to the background or when the screen has time out. Hence, to facilitate better user interaction, I have included in an Alert Dialog to inform user that the account has been logout due to session timeout and require them to re-login again. The session Timeout method functions normally and properly.
However, I am not able to get the wanted result when I place the AlertDialog method in onResume(). Below is the snippet of the code that has been done. Could anyone please help so that the AlertDialog can be displayed when the user resumes the activity.
//EDITED FOR SESSION LOGOUT
//WHEN APP IS IN IDLE OR WHEN USER DEVICE SCREEN IS OFF, WILL CALL ON THE METHOD TO LOGOUT USER
@Override
protected void onResume() {
super.onResume();
setloginButton();
EnquiryActivity.PROPERTY = 0;
//EDITED FOR SESSION LOGOUT
//Get the Resume Time
resumeDate = new Date();
long diff = resumeDate.getTime() - curDate.getTime();
long secInt = diff / 1000 % 60; //conversion of milliseconds into human readable form
if (secInt > Inactivity_Timeout){// SET EXIT SCREEN INTERVAL LOGOUT
IdleLogout();
AlertDialog();
}
}
@Override
public void onUserInteraction() {
super.onUserInteraction();
// TO LOG APP HAS EXITED AND IS PUSHED TO BACKGROUND PROCESS(25/08/2014)
Log.i("RootActivity:onUserInteraction","******APP ACTIVITY LOGGED******");
//CALL THE METHOD OF STARTUSERINACTIVITYDETECTTHREAD
startUserInactivityDetectThread();
// CREATING RECEIVE SCREEN_OFF & _ON BROADCAST MSGES FROM THE DEVICE.
new ScreenReceiver();
}
//Perform Check if User is still Login as an user
public void checkLogin(){
//CONDITION TO CHECK IF USER IS LOGIN, IF TRUE, CALL METHOD
....
}
public void startUserInactivityDetectThread(){
new Thread(new Runnable() {
public void run() {
// PROVIDING AN INFINITE LOOP WHEN FOLLOWING CONDITIONS ARE TRUE.
while(true) {
try {
Thread.sleep(10*1000);// CHECKS EVERY 10S SECS FOR USER INACTIVITY
//CONDITION SET TO CHECK ON FOLLOWING CONDITIONS, IF TRUE, PERFORM LOGOUT.
if(isScreenOff==true)
{
IdleLogout();
}
} catch (InterruptedException i) {
// TODO Auto-generated catch block
i.printStackTrace();
}
}
}
}).start();
}
public void IdleLogout(){
// Method to perform logout and erase shared preference credentials
.....
}
// TO INFORM USER ON THE STATUS OF LOGOUT WHEN USER RESUMES THE APP
public void AlertDialog() {
AlertDialog alertDialog = new AlertDialog.Builder(RootActivity.this).create();
alertDialog.setTitle("SESSION LOGOUT NOTICE");
alertDialog.setMessage("PLEASE LOGIN TO ACCESS YOUR PROFILE.");
//SETTING OF OK BUTTON
alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, "OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(getApplicationContext(), "You clicked on OK", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("market://details?id=com.og.ascendas.spacetobe"));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
}
});alertDialog.show();// SHOW ALERT MESSAGE
}
0 comments:
Post a Comment