im new in developing Android Apps.
I know how to set the starting Activity with the AndroidManifest.xml, but i need a way to check something first before i choose the starting Activity.
My Problem:
I created a loginActivity and a mainActivity.
I want to do the following: If i log me in, i’ll set a flag to 1 and at the next app start, i want show directly the mainActivity and not the login.
Is there any way to do that? I thought about creating a splashscreen where i can check if im logged in before showing the first Activity.
Thanks, Philip
Updated Code – working:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// get preferences
SharedPreferences userDetails = getApplicationContext().getSharedPreferences("userdetails", 0);
String savedEmail = userDetails.getString("email", "");
String savedPassword = userDetails.getString("password", "");
Boolean savedRemember = userDetails.getBoolean("remember", false);
Boolean savedLogged = userDetails.getBoolean("logged", false);
// check if already logged in
if(savedLogged) {
// start the overview
Intent intent = new Intent(this, ActivityOverview.class);
startActivity(intent);
finish();
}
else {
// initialize the form layout
setContentView(R.layout.activity_login);
// get views
this.email = (EditText)findViewById(R.id.editTextEmail);
this.password = (EditText)findViewById(R.id.editTextPassword);
this.remember = (CheckBox)findViewById(R.id.checkBoxRemember);
// set values to views
this.email.setText(savedEmail);
this.password.setText(savedPassword);
this.remember.setChecked(savedRemember);
}
}
I have something similar in one of my apps. I let the user chose weather it should auto-login or not. This is saved in the
SharedPreferences.When the app starts and in the mainpage, you should check – BEFORE the
setContentView(R.layout.activity_login);and setfinish();afterstartActivity();