title: Storing user credential data - on device & online
body: <p>I am writing an android application that requires the user to create an account and then login in order to access data pulled from an external source (and locally on device). I am trying to write the register code and am stuck on what the best approach to use.</p>
  
  <p>At the moment, I am thinking I should be creating shared preferences to store the username and password on the device and then writing the data to an external source via a db call. </p>
  
  <p>So what i want the workflow to look like is this:</p>
  
  <ol>
  <li>User opens application on device</li>
  <li>User is presented with splashscreen with "Login" and "Register" buttons.</li>
  <li>User selects "Register" and enters basic info (name,email,preferred username,password)</li>
  <li>User clicks Register button</li>
  <li>OnClick creates the shared preference and connects to the db to write the user credentials.</li>
  <li>User is re-directed to the main activity</li>
  <li>User closes app</li>
  <li>User opens app and is automatically logged into application.</li>
  </ol>
  
  <p>At the moment I have 2 classes, a register.java that contains the UI and an AccountPreferences.java that contains the logic. Is this the best approach?</p>
  
  <p>Also, is creating shared preferences and then creating a separate db call here the best solution? I tried looking into AccountManager but found this ridiculously complicated. I want to make sure I code it right the first time without having to re-write if there is a better way of doing this.</p>
  
  <p>Thanks in advance,</p>
  
  <p>Scott.</p>