---
title: "I am unable to retrieve the second value in Shared Preference"  
description: "I am unable to retrieve the second value in Shared Preference"  
author: "Manoj Bhatt"  
published: 2013-05-29  
updated: 2013-05-30  
canonical: https://www.mindstick.com/forum/936/i-am-unable-to-retrieve-the-second-value-in-shared-preference  
category: "android"  
tags: ["android"]  
reading_time: 2 minutes  

---

# I am unable to retrieve the second value in Shared Preference

Hi Everyone!\
In my example, i am entering mobile no., message [content](https://www.mindstick.com/articles/13019/get-the-best-content-marketing-pricing-packages-for-your-brand) in one [activity](https://www.mindstick.com/forum/12894/how-to-force-recreation-of-activity-fragment-on-restore). Before leaving that activity i am saving that info in "Shared Preference". In other activity i [am trying](https://answers.mindstick.com/qa/36834/which-two-programming-languages-should-i-master-in-if-i-am-trying-to-get-into-google-or-facebook) to get those mob no,message,i am able to get no but unable to getting that message(second value).please help me to [solve the issue](https://answers.mindstick.com/qa/95724/how-do-i-solve-the-issue-of-a-site-adheres-to-adsense).\
DefaultDetails.java\
package com.example.nirbhaya;\
import java.util.regex.Pattern;\
import android.app.Activity;import android.content.Intent;import android.content.SharedPreferences;import android.os.Bundle;import android.util.Log;import android.view.View;import android.view.View.[OnClickListener](https://www.mindstick.com/forum/33726/inside-onclicklistener-i-cannot-access-a-lot-of-things-how-to-approach);import android.widget.Button;import android.widget.EditText;import android.widget.Toast;\
public class DefaultDetails extends Activity implements OnClickListener{\
Button save,reset; EditText dMob,dMsg,dEmail; String defMobNo,defMsg,defEmail; SharedPreferences DefaultData;\
[private](https://www.mindstick.com/blog/11097/java-access-modifiers-the-public-and-the-private-modifiers) static final String TAG = "DD-Activity"; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.defaultdetails);\
initializing();\
} private void initializing() { // TODO Auto-generated method stub\
\
save = (Button)findViewById(R.id.bsave1); reset = (Button)findViewById(R.id.bReset);\
dMob = (EditText)findViewById(R.id.etDefMobNo); dMsg = (EditText)findViewById(R.id.etDefMsg); dEmail = (EditText)findViewById(R.id.etDefEmail);\
save.setOnClickListener(this); reset.setOnClickListener(this);\
\
} @Override [public void](https://www.mindstick.com/interview/2715/can-we-write-static-public-void-instead-of-public-static-void) onClick(View arg0) { // TODO Auto-generated method stub switch(arg0.getId()) { case R.id.bsave1: defMobNo = dMob.getText().toString(); defMsg = dMsg.getText().toString(); defEmail = dEmail.getText().toString(); Log.i(TAG,"DONE"); DefaultData = getSharedPreferences("defMobileNo",0); SharedPreferences.Editor store = DefaultData.edit(); store.putString("defMobileNo", defMobNo); store.putString("defMessgae", defMsg); store.putString("defEMail", defEmail); store.commit(); Intent openStartingPoint = new Intent (getApplicationContext(), CurrentDetails.class); startActivity(openStartingPoint); break; case R.id.bReset: ((EditText) findViewById(R.id.etDefMobNo)).setText(""); ((EditText) findViewById(R.id.etDefEmail)).setText(""); ((EditText) findViewById(R.id.etDefMsg)).setText(""); break; } }}DefSMS.java\
package com.example.nirbhaya;\
import android.app.Activity;import android.content.Intent;import android.content.SharedPreferences;import android.os.Bundle;import android.telephony.SmsManager;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.Toast;\
public class DefSms extends Activity{\
Button buttonSend; String defNo,defMsg; SharedPreferences DefaultData; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.defsms);\
DefaultData = getSharedPreferences("defMobileNo",0); final String defNo = DefaultData.getString("defMobileNo","Couldn't load data");\
DefaultData = getSharedPreferences("defMessgae",0); final String defMsg = DefaultData.getString("defMessgae","Couldn't load data");\
buttonSend = (Button) findViewById(R.id.buttonSend);\
buttonSend.setOnClickListener(new OnClickListener() {\
@Override public void onClick(View v) {\
try { SmsManager smsManager = SmsManager.getDefault(); smsManager.sendTextMessage(defNo, null, defMsg, null, null); Toast.makeText(getApplicationContext(), "SMS Sent!", Toast.LENGTH_LONG).show(); } catch ([Exception](https://www.mindstick.com/articles/1824/objective-c-exception-handling) e) { Toast.makeText(getApplicationContext(), "SMS faild, [please try again later](https://answers.mindstick.com/qa/94498/how-do-i-fix-the-please-try-again-later-problem-in-whatsapp)!", Toast.LENGTH_LONG).show(); e.printStackTrace(); }\
} });\
}}\
Here def no getting message as Couldn't load data please help me\
Thanks in [advance](https://www.mindstick.com/blog/33258/jee-mains-and-jee-advance-exams)!

## Replies

### Reply by AVADHESH PATEL

Hi Manoj!\
Replace you line of code with this:\

```
DefaultData = getSharedPreferences("defMobileNo",0);final String defNo = DefaultData.getString("defMobileNo","Couldn't load data");final String defMsg = DefaultData.getString("defMessgae","Couldn't load data");
```

\
It may be worked.


---

Original Source: https://www.mindstick.com/forum/936/i-am-unable-to-retrieve-the-second-value-in-shared-preference

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
