I want to make an int statement such that if there is a string saved on the local database, then do whatever. I tried:
public class DispatchActivity extends Activity {
SharedPreferences sharedPref;
SharedPreferences.Editor editor;
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
sharedPref= getSharedPreferences("myPref", Context.MODE_PRIVATE);
editor=sharedPref.edit();
String userIDsaved = sharedPref.getString("user_id", "");
if(userIDsaved==null){
Intent startSignUpActivity = new Intent(DispatchActivity.this,SignUpActivity.class);
DispatchActivity.this.startActivity(startSignUpActivity);
}
else{
Intent startMainActivity = new Intent(DispatchActivity.this,MainActivity.class);
DispatchActivity.this.startActivity(startMainActivity);
}
...
However the app crashes when I do that. This is a dispatch activity, meaning if there is a string found locally, then start the mainactivity. if not, start the sign up activity. Even If i do have a string saved locally, then it crashes. Please tell me how to do what I mentioned
Aucun commentaire:
Enregistrer un commentaire