功能:
创建了警报对话框方法以通知用户帐户的状态,因此,当用户远程注销时,将弹出对话框。此外,应用程序中有4个活动;因此,当记录帐户时,当用户决定导航到下一个活动时,将弹出对话框。然后,对话框弹出窗口将在确认后将用户导航回登录页面。
问题:
当用户帐户注销后,警报对话框不会弹出,注销bttn已更改为登录并且已清除共享首选项凭据。它仍然允许用户在应用程序中导航,应用程序将在延迟的时间段后显示。
代码和建议出了什么问题?
代码
//Build an AlertDialog to notify user on Session Logout status
static Builder alertDialog(final Activity act,final Intent yourintent){
Log.i("RootActivity:alertDialog","******Session Logout Info******");
AlertDialog.Builder alertDialog = new AlertDialog.Builder(act);
alertDialog.setTitle("Sign In For Spacetobe Services");
alertDialog.setMessage("For security reasons, you have been automatically logged out after 20 minutes of inactivity." +
"To access Spacetobe services, please sign in again.");
alertDialog.setCancelable(false);
//SETTING OF OK BUTTON
alertDialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
//Intent yourintent = new Intent(Intent.ACTION_VIEW);
//yourintent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
act.startActivity(yourintent);//Return page to PROPERTYACTIVITY
}
}); return alertDialog;
}
//LOGOUT METHOD & CLEARING OF SHARED PREFERENCE CREDENTIALS
public void IdleLogout(){
Log.i("RootActivity:IdleLogout()","******APP LOGGEDOUT******");
//SharedPreference method cleared
Log.i("RootActivity:IdleLogout()","******loginButton is set******");
setloginButton(); // Change logout button to login
checkTimeout=true; // Global timeout is true
//RootActivity.alertDialog(this,getCustomIntent(PropertyActivity.class)).create().show();
}
//EDITED VERSION TO GET LOGOUT DIALOG WHEN USER TRIES TO NAVIGATE TO OTHER ACTIVITY BY BACK BTTN WHEN LOGGED OUT
@Override
public void onBackPressed(){
Log.i("RootActivity:onBackPreseed()","******Back bttn has been selected******");
if (checkTimeout==true){
Log.i("RootActivity:onCreate(Bundle savedInstanceState)","******Timeout=true******");
RootActivity.alertDialog(this,getCustomIntent(PropertyActivity.class)).create().show();
checkTimeout = false;
}return;
}
//END OF EDITED VERSION TO GET LOGOUT DIALOG WHEN USER TRIES TO NAVIGATE TO OTHER ACTIVITY BY BACK BTTN WHEN LOGGED OUT
// For each new individual activity
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
context = this;
//EDITED VERSION TO GET START TIME FOR EACH USER INTERACTION WITH THE ACTIVITY
startTime=System.currentTimeMillis();
Log.i("RootActivity:onCreate(Bundle savedInstanceState)","******startTime=******"+startTime);
//END OF EDITED VERSION TO GET START TIME FOR EACH USER INTERACTION WITH THE ACTIVITY
//EDITED VERSION TO GET LOGOUT DIALOG WHEN USER TRIES TO NAVIGATE TO OTHER ACTIVITY WHEN LOGGED OUT
if (checkTimeout==true){
Log.i("RootActivity:onCreate(Bundle savedInstanceState)","******Timeout=true******");
RootActivity.alertDialog(this,getCustomIntent(PropertyActivity.class)).create().show();
checkTimeout = false;
}return;
//END OF EDITED VERSION TO GET LOGOUT DIALOG WHEN USER TRIES TO NAVIGATE TO OTHER ACTIVITY WHEN LOGGED OUT
}
答案 0 :(得分:1)
将对话框代码移动到onResume()方法,此时,活动可见。