AWS Cognito:如何保持Android用户登录状态?

时间:2018-07-26 20:04:08

标签: android mobile amazon-cognito aws-cognito aws-mobilehub

当前,每次重新启动应用程序时,用户都必须登录。我希望应用程序记住用户,直到他们手动注销为止。以下是我认为可行的方法,但它完全绕过了登录活动。

popupWinindow.document.write('<html><head><style>.floor-plan { background-color: #eaf3f3;  border-radius: 2px;  }  .floor-plan svg { /* Is needed because svg is by default inline-block and thusthe wrapping div would get higher by some extra pixels.See https://stackoverflow.com/questions/24626908/*/  display: block;  }  .floor-plan .boundary {  fill: transparent;  stroke: #0A7A74;  stroke-width: 2px;  }  .dining-table rect, .dining-table ellipse {  fill: transparent;  stroke: #0A7A74;  stroke-width: 2px;  }  .dining-table.assigned rect, .dining-table.assigned ellipse {  fill: #0a7a74;  }  .dining-table.assigned tspan {  fill: #ffffff;  }  .dining-table.hasSpecialInformation rect, .dining-table.hasSpecialInformation ellipse {  stroke: red;  }  .dining-table.hasOnlyBreakfast rect, .dining-table.hasOnlyBreakfast ellipse {  fill: #0d2f2e;  }  .dining-table image {  opacity: 0.5;  }  tspan.table-number {  fill: #666;  }  tspan.guest-info {fill: #333; font-weight: bolder;  } </style></head><body onload="window.print()">' + innerContents + '</html>');

因此,即使我单击登录按钮后才创建CognitoUser对象,@Override protected void onStart() { super.onStart(); if(userPool.getCurrentUser() != null){ Intent intent = new Intent(LoginActivity.this, MainActivity.class); finish(); startActivity(intent); } } 开头也不能为空。

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

设置用户池客户端,以使刷新令牌具有最大到期时间。首次登录时,保存刷新令牌。然后,每次重新启动应用程序时,请使用刷新令牌刷新当前用户会话并获取新的ID /访问令牌