0

as i m new to android application development .. i m making a passwords manager type of application ... so on the first page i have asked for username and password and a button for signup. if a person is running application for first time then he/she has to sign up and provide user id,password,security question for the case if he/she forgets his/her password. now i want to save the user id and password which user provide during signup in the application and next time when he/she again login and enters the user id and password then application should verify it from the saved user id and password and direct it to next page if he/she entered correct user id and password else a message should toast that "incorrect username or password ".

for this what coding in eclipse should i do..?

i had already made xml files i.e layouts..

thanks

parthcool94
  • 3
  • 1
  • 4
  • I will like to point you to this: [http://stackoverflow.com/questions/785973/what-is-the-most-appropriate-way-to-store-user-settings-in-android-application][1] [1]: http://stackoverflow.com/questions/785973/what-is-the-most-appropriate-way-to-store-user-settings-in-android-application – Thomas Oct 01 '12 at 07:24

1 Answers1

5

You should save it in a file, i recommend using SharedPreferences and then read it from there each time they start the application, and see if the matches are correct or not.

To save it:

SharedPreferences sp = context.getSharedPreferences("loginSaved", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sp.edit();
editor.putString("username", "some user value");
editor.putString("password", "some password value");
editor.commit();

To get it:

SharedPreferences sp = context.getSharedPreferences("loginSaved", Context.MODE_PRIVATE);
String username = sp.getString("username", null);
String password = sp.getString("password", null);
if(username != null && password != null){
    // login automatically with username and password    
}
else{
    // login for the first time
}
Carnal
  • 21,744
  • 6
  • 60
  • 75
  • thanks for your answer but will u please answer it in more detail that wat should i do?? as m new in android developement... – parthcool94 Oct 01 '12 at 07:16
  • I think you should read the documentation. SharedPreferences is an xml file where you can store values. So if your application shuts down, these values will still be available when you start it up. – Carnal Oct 01 '12 at 07:22