Reputation: 41
Scenario is that I have a splash screen which reads a password from device. If found password then go to Main Activity, else, go to other activity.
I have problem in making condition. Kindly help me out for example:
SharedPreferences oPref = getActivity().getSharedPreferences("RegistrationData",Context.MODE_PRIVATE);
String pin = oPref.getString("mobileNumebr", " ");
Upvotes: 0
Views: 133
Reputation: 4570
Try this code
String pin = oPref.getString("mobileNumebr", " ");
new CountDownTimer(3000, 1000) {
@Override
public void onTick(long millisUntilFinished) {
}
@Override
public void onFinish() {
if (pin.equals("")) {
startActivity(new Intent(SplashPage.this, LoginActivity.class));
} else {
startActivity(new Intent(SplashPage.this, HomePage.class));
}
finish();
}
}.start();
Upvotes: 2
Reputation: 1522
You should use the TextUtills class of android and check like this:
SharedPreferences oPref = getActivity().getSharedPreferences("RegistrationData",Context.MODE_PRIVATE);
String pin = oPref.getString("mobileNumebr", "");//default value should be empty
if(TextUtills.isEmpty(pin)){
//Go to main activity
}else {
//Go to login Activity
}
Thanks
Upvotes: 2
Reputation: 1969
Try this.
String pin = oPref.getString("mobileNumebr", "");
if(pin.equalsIgnoreCase(""))
{
go to other activity
}
else
{
go to main activity
}
Hope it helps
Upvotes: 2
Reputation: 3520
Try this out
String pin=String pin = oPref.getString("mobileNumebr", "");
if(pin!=null && !pin.isEmpty()){
--go to main activity--
}else{
-- go to other activity--
}
Upvotes: 0