【发布时间】:2014-09-18 15:14:26
【问题描述】:
手头的问题:
当应用程序被推到后台或屏幕超时时,应用程序本身将执行自动会话超时注销。因此,为了促进更好的用户交互,我在警报对话框中包含了一个通知用户该帐户由于会话超时而已注销并要求他们再次重新登录。会话 Timeout 方法运行正常且正常。
但是,当我将 AlertDialog 方法放在 onResume() 中时,我无法获得想要的结果。下面是已经完成的代码的sn-p。任何人都可以帮忙,以便在用户恢复活动时显示 AlertDialog。
//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)
.....
}
//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) {
//Perform Thread to check on condition and run idlelogout
}
}
}).start();
}
public void IdleLogout(){
// Method to perform logout and erase shared preference credential
}
// 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.setPositiveButton("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
}
【问题讨论】:
-
你把你的方法命名为和类(AlertDialog)一样吗??
-
@SagarPilkhwal 我运行 Logcat 时它没有登录!!我实际上不能将 alertdialog 方法放在循环条件原因之外,这将导致函数失败,因为用户将无法登录并且 alertdialog 消息不断显示
-
@SagarPilkhwal,一点也不。还在尝试
-
@SagarPilkhwal 是的,idlelogout 方法在 if (secInt > Inactivity_Timeout){} 循环内工作
-
@SagarPilkhwal 所以我可以知道你在暗示什么吗?我还是没听懂。
标签: android user-interface android-alertdialog session-timeout