私は異なるタイプのユーザーに基づいて読み込む3つのアクティビティを持っています。ログイン時にsharedpreferencesにログインしたユーザー情報を保存しました。私はログアウトボタンをクリックした後にユーザー情報を削除します。ログアウトユーザーが自動的にアプリにサインインできるようになるまで、sharedpreferencesにレコードが存在するかどうか確認する必要があります。どうやってするの。ここに私のコードは次のとおりです。あなたのランチャーの活動にログインユーザーがアンドロイドのsharedpreferencesに情報がある場合に自動的にサインインする方法
try {
object = new JSONObject(root.getTextContent().toString());
StatusValue = object.getString("status");
UserInfoValue = object.getString("UserInfo");
} catch (JSONException e) {
e.printStackTrace();
}
SharedPreferences.Editor editor = getSharedPreferences("UserInfoValues", MODE_PRIVATE).edit();
editor.putString("UserInfos", UserInfoValue);
editor.commit();
// Log.d("Value:" ,Value);
txtView.setText(StatusValue);
if(StatusValue.equalsIgnoreCase("success"))
{
String userType = null;
//SharedPreferences prefs = getSharedPreferences("UserInfoValues", MODE_PRIVATE);
// String restoredText = prefs.getString("UserInfos", null);
try {
JSONObject infoObject = new JSONObject(UserInfoValue);
userType = infoObject.getString("UserType");
} catch (JSONException e) {
e.printStackTrace();
}
if(userType.equalsIgnoreCase("NormalUser"))
{
Intent intent=new Intent(LoginActivity.this,NewBookingActivity.class);
startActivity(intent);
Toast.makeText(getApplicationContext(), "Successfully Loged In As Normal User", Toast.LENGTH_LONG).show();
finish();
}
if(userType.equalsIgnoreCase("HelpDesk"))
{
Intent intent=new Intent(LoginActivity.this,DriverActivity.class);
startActivity(intent);
Toast.makeText(getApplicationContext(), "Successfully Loged In As HelpDesk User", Toast.LENGTH_LONG).show();
finish();
}
if(userType.equalsIgnoreCase("Car"))
{
Intent intent=new Intent(LoginActivity.this,DriverActivity.class);
startActivity(intent);
Toast.makeText(getApplicationContext(), "Successfully Loged In As Car User", Toast.LENGTH_LONG).show();
finish();
}
ので、私は」:あなたのスプラッシュがこれを置く使用場所、その後
あなたはそのフィールドを削除することができます "タイプ"を使用しました。 –