Login screen remember functionality
<p>I am new to android , this question is a repost as for some reasons i was not able to update the previous one.
I am able to create remember me functionality in my login page, when i restart my app the username and password field are already filled but i have to click on the login button to get to another activity.</p>

<p>How to code if i want to directly load another activity if remember me checkbox is true rather than clicking on the login button again when i again load my application.</p>

<pre><code>  public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_main);

        b = (Button)findViewById(R.id.Button01);  
        et = (EditText)findViewById(R.id.username);
        pass= (EditText)findViewById(R.id.password);
        register = (TextView)findViewById(R.id.register);
        saveLoginCheckBox = (CheckBox)findViewById(R.id.remember);
        loginPreferences = getSharedPreferences("loginPrefs", MODE_PRIVATE);
        loginPrefsEditor = loginPreferences.edit();

        saveLogin = loginPreferences.getBoolean("saveLogin", false);
        if (saveLogin == true) {
            //uname = et.getText().toString();
           // pwd = pass.getText().toString();
            et.setText(loginPreferences.getString("uname", ""));
            pass.setText(loginPreferences.getString("pwd", ""));
            saveLoginCheckBox.setChecked(true);
          login();
         //  finish();
        }



         b.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog = ProgressDialog.show(MainActivity.this, "", 
                        "Validating user...", true);
                 new Thread(new Runnable() {
                        public void run() {
                             uname = et.getText().toString();
                             pwd = pass.getText().toString();

                             if (saveLoginCheckBox.isChecked()) {
                                 loginPrefsEditor.putBoolean("saveLogin", true);
                                 loginPrefsEditor.putString("uname", uname);
                                 loginPrefsEditor.putString("pwd", pwd);
                                 loginPrefsEditor.commit();
                             } else {
                                 loginPrefsEditor.clear();
                                 loginPrefsEditor.commit();
                             }


                          login();

                        }
                      }).start();               
            }
        });



 register.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                //dialog = ProgressDialog.show(MainActivity.this, "", 
               //         "Loading...", true);
                new Thread(new Runnable(){
                    public void run(){

                    register();
                }
                    }).start();
            }
        });

        }



    void register(){
        startActivity(new Intent(MainActivity.this,RegisterPage.class));


    }

    void login(){
        try{            

            httpclient=new DefaultHttpClient();
            httppost= new HttpPost("http://192.168.10.71/login.php"); // make sure the url is correct.
            //add your data
            nameValuePairs = new ArrayList&lt;NameValuePair&gt;(2);
            // Always use the same variable name for posting i.e the android side variable name and php side variable name should be similar, 
            nameValuePairs.add(new BasicNameValuePair("username",et.getText().toString()));  // $Edittext_value = $_POST['Edittext_value'];
            nameValuePairs.add(new BasicNameValuePair("password",pass.getText().toString())); 
            httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
            //Execute HTTP Post Request
          //  response=httpclient.execute(httppost);
            ResponseHandler&lt;String&gt; responseHandler = new BasicResponseHandler();
            final String response = httpclient.execute(httppost, responseHandler);
          //  System.out.println("Response : " + response); 
           /* runOnUiThread(new Runnable() {
                public void run() {
                    tv.setText(response + et.getText());
                    dialog.dismiss();
                }
            });
*/             
            if(response.equalsIgnoreCase("Doctor Found")){
                runOnUiThread(new Runnable() {
                    public void run() {
                        //tv.setText(response);
                        dialog.dismiss();
                        Toast.makeText(MainActivity.this,"Hello Doctor  " + et.getText(), Toast.LENGTH_SHORT).show();
                    }
                });

                startActivity(new Intent(MainActivity.this, DoctorPage.class));

            }
            else if(response.equalsIgnoreCase("Nurse Found")){
                runOnUiThread(new Runnable() {
                    public void run() {
                        //tv.setText(response);
                        dialog.dismiss();
                        Toast.makeText(MainActivity.this,"Hello Nurse  " + et.getText(), Toast.LENGTH_SHORT).show();
                    }
                });

                startActivity(new Intent(MainActivity.this, NursePage.class));

            }            
            else{
                showAlert();  
                dialog.dismiss();
            }

        }catch(Exception e){
            dialog.dismiss();
            System.out.println("Exception : " + e.getMessage());
        }
    }
</code></pre>

<p>I am getting Null Pointer Exception . I am not able to switch to another activity if the remember me box is checked. Here is the stack trace.</p>

<pre><code>05-21 04:13:02.284: E/AndroidRuntime(3397): FATAL EXCEPTION: main
05-21 04:13:02.284: E/AndroidRuntime(3397): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.logincheck/com.example.logincheck.MainActivity}: java.lang.NullPointerException
05-21 04:13:02.284: E/AndroidRuntime(3397):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
05-21 04:13:02.284: E/AndroidRuntime(3397):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
05-21 04:13:02.284: E/AndroidRuntime(3397):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
05-21 04:13:02.284: E/AndroidRuntime(3397):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
05-21 04:13:02.284: E/AndroidRuntime(3397):     at android.os.Handler.dispatchMessage(Handler.java:99)
05-21 04:13:02.284: E/AndroidRuntime(3397):     at android.os.Looper.loop(Looper.java:137)
05-21 04:13:02.284: E/AndroidRuntime(3397):     at android.app.ActivityThread.main(ActivityThread.java:5041)
05-21 04:13:02.284: E/AndroidRuntime(3397):     at java.lang.reflect.Method.invokeNative(Native Method)
05-21 04:13:02.284: E/AndroidRuntime(3397):     at java.lang.reflect.Method.invoke(Method.java:511)
05-21 04:13:02.284: E/AndroidRuntime(3397):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
05-21 04:13:02.284: E/AndroidRuntime(3397):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
05-21 04:13:02.284: E/AndroidRuntime(3397):     at dalvik.system.NativeStart.main(Native Method)
05-21 04:13:02.284: E/AndroidRuntime(3397): Caused by: java.lang.NullPointerException
05-21 04:13:02.284: E/AndroidRuntime(3397):     at com.example.logincheck.MainActivity.login(MainActivity.java:182)
05-21 04:13:02.284: E/AndroidRuntime(3397):     at com.example.logincheck.MainActivity.onCreate(MainActivity.java:68)
05-21 04:13:02.284: E/AndroidRuntime(3397):     at android.app.Activity.performCreate(Activity.java:5104)
05-21 04:13:02.284: E/AndroidRuntime(3397):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
05-21 04:13:02.284: E/AndroidRuntime(3397):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
05-21 04:13:02.284: E/AndroidRuntime(3397):     ... 11 more
</code></pre>

<p>note : i want something like we have on facebook . After entering username, password and check the remember me checkbox if i open the facebook page again then my homepage will appear rather than the welcome screen where i have to just click on login button.</p>
