title: Android: user login and stays in session until logout (which needs approval)
body: <p>I would like to make sure that when user log in it will stay in session no matter what happens (crashed, shut down/power down/reboot, leaving the app) at same time the user info data will be sending with all the activities in the app to the webserver. </p>
  
  <p>for example at the start up of the app, user login '9999' it goes to the main activity that have 5 diff. activities. user 9999 will send one activity (i.e. gps location) it will send that info to the webserver as user 9999 gps 123.234 123.123.</p>
  
  <p>I want to ensure the users stays in session and also send its users data with the "activity" data sent. 
  I read this link</p>
  
  <p><a href="https://stackoverflow.com/questions/785973/what-is-the-most-appropriate-way-to-store-user-settings-in-android-application">What is the most appropriate way to store user settings in Android application</a></p>
  
  <p>I was still unable to put it together.</p>
  
  <p>At the same time in the same main screen it has a logout. User needs manager approval to logout by inputting the code(i.e. 1234) to completely logout and for new user to input their id number. I want to know how to put the hardcode '1234' within the activity.</p>
  
  <p>this code is my main screen after login to give you the idea</p>
  
  <pre><code> MainActivity.java
  
   import android.app.ListActivity;
   import android.content.Intent; import
   android.os.Bundle; import
   android.view.View; import
   android.widget.ArrayAdapter; import
   android.widget.ListView; import
   android.widget.TextView;
  
   public class Customer extends ListActivity {TextView selection;
       CustomerListItem[] items ={
            new CustomerListItem("Start Trip",StartTripActivity.class), 
           new CustomerListItem("Clock in",ClockinActivity.class), 
           new CustomerListItem("Customer Svc",CustomerSvcActivity.class), 
           new CustomerListItem("IndependentInspection",InspectionActivity.class), 
           new CustomerListItem("Pick Up", PickUpActivity.class), 
           new CustomerListItem("Log Out", LogoutActivity.class)};    
  
  private TextView resultsTxt;
  
       @Override
       public void onCreate(Bundle icicle)
       {
           super.onCreate(icicle);
           setContentView(R.layout.main);
           setListAdapter(new ArrayAdapter&lt;CustomerListItem&gt;(
                   this, android.R.layout.simple_list_item_1,
   items));
           selection = (TextView) findViewById(R.id.selection);
       }
  
       @Override
       protected void onListItemClick(ListView l, View v,
   int position, long id)
       {
           super.onListItemClick(l, v, position, id);
           final Intent intent = new Intent(this,
   items[position].getActivity());
           startActivityForResult(intent, position);
       }
  
       @Override
       protected void onActivityResult(int requestCode, int
   resultCode, Intent intent)
       {
           super.onActivityResult(requestCode,
   resultCode, intent);
           if (resultCode == RESULT_OK)
           {
               // Perform different actions based on from which activity is
               // the application returning:
               switch (requestCode)
               {
                  case 0:
              // TODO: handle the return of the StartTripActivity
              break;
          case 1:
              // TODO: handle the return of the ClockinActivity
              break;
          case 2:
              // TODO: handle the return of the CustomerSvcActivity
          case 3:
              // TODO: handle the return of the InspectionActivity
              break;
          case 4:
              // TODO: handle the return of the PickUpActivity
              break;
          case 5:
              // TODO: handle the return of the LogoutActivity
              break;
          default:
              break;
               }
           }
           else if (resultCode == RESULT_CANCELED)
           {
               resultsTxt.setText("Canceled");
           }
       } }
  </code></pre>
  
  <p>UPDATE: </p>
  
  <p>Login.java</p>
  
  <pre><code>import android.app.Activity;
  import android.content.Intent;
  import android.os.Bundle;
  import android.view.View;
  import android.view.View.OnClickListener;
  import android.widget.Button;
  import android.widget.EditText;
  import android.widget.TextView;
  
  
  public class Login extends Activity {
      private EditText etUsername;
      private Button btnLogin;
      private Button btnCancel;
      private TextView lblResult;
      /** Called when the activity is first created. */
      //@Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.login);
  
          etUsername = (EditText)findViewById(R.id.username);
          btnLogin = (Button)findViewById(R.id.login_button);
          btnCancel = (Button)findViewById(R.id.cancel_button);
          lblResult = (TextView)findViewById(R.id.result);
  
          btnLogin.setOnClickListener(new OnClickListener() {
              //@Override
              public void onClick(View v) {
              // Check Login
              String username = etUsername.getText().toString();
  
              if(username.equals("guest")){
                  lblResult.setText("Login successful.");
  
  
  
  
                  Intent i = new Intent(getApplicationContext(), Customer.class);
                  startActivity(i);
  
              } else {
                   lblResult.setText("Login failed. Username doesn't match.");
               }
              }
              });
  
  
              btnCancel.setOnClickListener(new OnClickListener() {
              //@Override
              public void onClick(View v) {
                 // Close the application
              finish();
                  }
              });
      }
  }
  </code></pre>