contact picker activity stores data, unless back button pressed
<p>I have searched &amp; searched but can't seem to figure this out:<br>
I have an activity that opens then you push a button which brings up contact picker. Upon selecting contact it returns to activity and puts name and # in their respective boxes. Now, I push home button , select the app again to reopen and the values are still their.. which is good, but when i push the 'back' button my program closes and when reopened loses its values</p>

<pre><code>public class speed_dial_setup extends Activity {
/** Called when the activity is first created. */
 private static final int CONTACT_PICKER_RESULT1 = 1001;
 private static final int CONTACT_PICKER_RESULT2 = 2002;
 private static final int CONTACT_PICKER_RESULT3 = 3003;
 private static final int CONTACT_PICKER_RESULT4 = 4004;
 private static final int CONTACT_PICKER_RESULT5 = 5005;
private static final String DEBUG_TAG = null;
EditText pNumber1;
Button cPICKER1,cPICKER2,cPICKER3,cPICKER4, cPICKER5;
// SharedPreferences sharedPref = getSharedPreferences("pNumber1",MODE_PRIVATE);
// String webViewChoice = sharedPref.getString("pNumber1","null"); 

private static final String empty = "";
private static String selectedNumber = "", selectedName = "";
private static String phoneNumber = "", phoneName = ""; 
public static String name1 = "", name2 = "", name3 = "", name4 = "", name5 = "";
public static String phone1 = "", phone2 = "", phone3 = "", phone4 = "", phone5 = "";

private EditText phName1, phName2, phName3, phName4, phName5;
private EditText phNumb1, phNumb2, phNumb3, phNumb4, phNumb5;

SharedPreferences sharedPref;
SharedPreferences.Editor prefEditor;

private static int phoneIdx = 0, nameIdx = 0;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.main);

    cPICKER1 = (Button) findViewById(R.id.do_email_picker1);
    cPICKER2 = (Button) findViewById(R.id.do_email_picker2);
    cPICKER3 = (Button) findViewById(R.id.do_email_picker3);
    cPICKER4 = (Button) findViewById(R.id.do_email_picker4);
    cPICKER5 = (Button) findViewById(R.id.do_email_picker5);

    phName1 = (EditText) findViewById(R.id.name_text1);
    phName2 = (EditText) findViewById(R.id.name_text2);
    phName3 = (EditText) findViewById(R.id.name_text3);
    phName4 = (EditText) findViewById(R.id.name_text4);
    phName5 = (EditText) findViewById(R.id.name_text5);

    phNumb1 = (EditText) findViewById(R.id.phone_number1);
    phNumb2 = (EditText) findViewById(R.id.phone_number2);
    phNumb3 = (EditText) findViewById(R.id.phone_number3);
    phNumb4 = (EditText) findViewById(R.id.phone_number4);
    phNumb5 = (EditText) findViewById(R.id.phone_number5);

        pNumber1 = (EditText) findViewById(R.id.phone_number1);

    cPICKER1.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            // TODO Auto-generated method stub
             Intent contactPickerIntent = new Intent(Intent.ACTION_PICK,
                        Contacts.CONTENT_URI);
                startActivityForResult(contactPickerIntent, CONTACT_PICKER_RESULT1);

        }
    });


    cPICKER2.setOnClickListener(new View.OnClickListener() {

    public void onClick(View v) {
        // TODO Auto-generated method stub
         Intent contactPickerIntent2 = new Intent(Intent.ACTION_PICK,
                    Contacts.CONTENT_URI);
            startActivityForResult(contactPickerIntent2, CONTACT_PICKER_RESULT2);

    }
});


cPICKER3.setOnClickListener(new View.OnClickListener() {

    public void onClick(View v) {
        // TODO Auto-generated method stub
         Intent contactPickerIntent3 = new Intent(Intent.ACTION_PICK,
                    Contacts.CONTENT_URI);
            startActivityForResult(contactPickerIntent3, CONTACT_PICKER_RESULT3);

    }
});

cPICKER4.setOnClickListener(new View.OnClickListener() {

    public void onClick(View v) {
        // TODO Auto-generated method stub
         Intent contactPickerIntent4 = new Intent(Intent.ACTION_PICK,
                    Contacts.CONTENT_URI);
            startActivityForResult(contactPickerIntent4, CONTACT_PICKER_RESULT4);

    }
});


cPICKER5.setOnClickListener(new View.OnClickListener() {

    public void onClick(View v) {
        // TODO Auto-generated method stub
         Intent contactPickerIntent5 = new Intent(Intent.ACTION_PICK,
                    Contacts.CONTENT_URI);
            startActivityForResult(contactPickerIntent5, CONTACT_PICKER_RESULT4);

    }
});

    }

   protected void onActivityResult(int requestCode, int resultCode, Intent data) {  
    if (resultCode == RESULT_OK)
    {           
        Cursor cursor = null;  
        phoneNumber = "";
        phoneName   = "";

        List&lt;String&gt; allNumbers = new ArrayList&lt;String&gt;();


        try 
        {  
            Uri result = data.getData();  
            String id = result.getLastPathSegment(); 

            cursor = getContentResolver().query(Phone.CONTENT_URI, null, 
                Phone.CONTACT_ID + "=?", new String[] { id }, null);  

            phoneIdx = cursor.getColumnIndex(Phone.DATA);                    
            nameIdx  = cursor.getColumnIndex(Phone.DISPLAY_NAME);

            if (cursor.moveToFirst()) {
                while (cursor.isAfterLast() == false) {
                    phoneNumber = cursor.getString(phoneIdx);
                    phoneName = cursor.getString(nameIdx);

                    allNumbers.add(phoneNumber);
                    cursor.moveToNext();
                }
            } 
            else 
            {
                //no results actions
            }                
        } 
        catch (Exception e) 
        {  
           //error actions
        } 
        finally 
        {  
            if (cursor != null)
            {  
                cursor.close();
            }

        final CharSequence[] items = allNumbers.toArray(new String[allNumbers.size()]);
        AlertDialog.Builder builder = new AlertDialog.Builder(speed_dial_setup.this);
        builder.setTitle("Choose a number");
        builder.setItems(items, new DialogInterface.OnClickListener() 
        {
            public void onClick(DialogInterface dialog, int item) 
            {
                selectedNumber = items[item].toString();
                selectedNumber = selectedNumber.replace("-", "");
            }
        });

        AlertDialog alert = builder.create();

        if(allNumbers.size() &gt; 1) 
        {
            alert.show();
        }
        else 
        {
            selectedNumber = phoneNumber.toString();
            selectedNumber = selectedNumber.replace("-", "");

            selectedName = phoneName.toString();
        }

        if (phoneNumber.length() == 0) 
        {
            Toast.makeText(this, "No phone number found for contact.",  
                    Toast.LENGTH_LONG).show();   
        }
        }
    }
    else 
    {
        Log.w(DEBUG_TAG, "Warning: activity result not ok");
    } 

    /*********/
    switch (requestCode) 
    {  
    case CONTACT_PICKER_RESULT1:
        phNumb1.setText(selectedNumber);
        phName1.setText(selectedName);

        name1 = selectedName;
        phone1 = selectedNumber;

        SharedPreferences sharedPref = getSharedPreferences("com.pick.contact",MODE_PRIVATE); 
        SharedPreferences.Editor prefEditor = sharedPref.edit(); 
        prefEditor.putString("pNumber1",selectedNumber); 
        prefEditor.commit(); 

        System.err.println("Chp1, phoneNumber = "+phoneNumber+" phoneName = "+phoneName);
        break;

    case CONTACT_PICKER_RESULT2:
        phNumb2.setText(selectedNumber);
        phName2.setText(selectedName);

        name2 = selectedName;
        phone2 = selectedNumber;

        sharedPref = getSharedPreferences("com.pick.contact",MODE_PRIVATE); 
        prefEditor = sharedPref.edit(); 
        prefEditor.putString("pNumber1",selectedNumber); 
        prefEditor.commit(); 

        System.err.println("Chp2, phoneNumber = "+phoneNumber+" phoneName = "+phoneName);
        break;  

    case CONTACT_PICKER_RESULT3:
        phNumb3.setText(selectedNumber);
        phName3.setText(selectedName);

        name3 = selectedName;
        phone3 = selectedNumber;

        sharedPref = getSharedPreferences("com.pick.contact",MODE_PRIVATE); 
        prefEditor = sharedPref.edit(); 
        prefEditor.putString("pNumber1",selectedNumber); 
        prefEditor.commit(); 

        System.err.println("Chp3, phoneNumber = "+phoneNumber+" phoneName = "+phoneName);
        break;      

    case CONTACT_PICKER_RESULT4:
        phNumb4.setText(selectedNumber);
        phName4.setText(selectedName);

        name4 = selectedName;
        phone4 = selectedNumber;

        sharedPref = getSharedPreferences("com.pick.contact",MODE_PRIVATE); 
        prefEditor = sharedPref.edit(); 
        prefEditor.putString("pNumber1",selectedNumber); 
        prefEditor.commit(); 

        System.err.println("Chp4, phoneNumber = "+phoneNumber+" phoneName = "+phoneName);
        break; 

    case CONTACT_PICKER_RESULT5:
        phNumb5.setText(selectedNumber);
        phName5.setText(selectedName);

        name5 = selectedName;
        phone5 = selectedNumber;

        sharedPref = getSharedPreferences("com.pick.contact",MODE_PRIVATE); 
        prefEditor = sharedPref.edit(); 
        prefEditor.putString("pNumber1",selectedNumber); 
        prefEditor.commit(); 

        System.err.println("Chp5, phoneNumber = "+phoneNumber+" phoneName = "+phoneName);
        break;  
    }
}


@Override
protected void onResume() {
    // TODO Auto-generated method stub
    super.onResume();
    super.onPause();
    SharedPreferences sharedPref = getSharedPreferences("speed_dial_setup",MODE_PRIVATE);
    SharedPreferences.Editor prefEditor = sharedPref.edit();
    prefEditor.putString("pNumber1","phone_number");
    prefEditor.commit(); 

}


@Override
protected void onStop() {
    // TODO Auto-generated method stub
    // super.onStop();
    super.onPause();
    SharedPreferences sharedPref = getSharedPreferences("speed_dial_setup",MODE_PRIVATE);
    SharedPreferences.Editor prefEditor = sharedPref.edit();
    prefEditor.putString("pNumber1","phone_number");
    prefEditor.commit(); 
}


@Override
protected void onPause() {
    // TODO Auto-generated method stub
    super.onPause();
    SharedPreferences sharedPref = getSharedPreferences("speed_dial_setup",MODE_PRIVATE);
    SharedPreferences.Editor prefEditor = sharedPref.edit();
    prefEditor.putString("pNumber1","phone_number");
    prefEditor.commit(); 
}


@Override
protected void onDestroy() {
    // TODO Auto-generated method stub
    //super.onDestroy();
    super.onPause();
    SharedPreferences sharedPref = getSharedPreferences("speed_dial_setup",MODE_PRIVATE);
    SharedPreferences.Editor prefEditor = sharedPref.edit();
    prefEditor.putString("pNumber1","phone_number");
    prefEditor.commit(); 
}
}
</code></pre>
