Step 1:
Set Method
int user_id=bean.getId();
store(user_id);
private void store(int userID){ SharedPreferences.Editor editor = getSharedPreferences(MY_PREFS_NAME, MODE_PRIVATE).edit(); editor.putInt("User_id", userID); editor.commit(); }
Get Method
private int getUserID(){ SharedPreferences prefs = getSharedPreferences(MY_PREFS_NAME, MODE_PRIVATE); int user_id = prefs.getInt("User_id", 0); return user_id; }int id=getUserID();
if(id == 0){ Intent intent = new Intent(SplashActivity.this, LoginActivity.class); startActivity(intent); finish(); }else{ Intent i=new Intent(SplashActivity.this,MainActivity.class); startActivity(i); finish(); }
No comments:
Post a Comment