[android-developers] Re: SharedPreferences no work

2012-12-14 Thread bob


On Friday, December 14, 2012 2:23:46 AM UTC-6, Antonis Kanaris wrote:
>
>
>
> Τη Παρασκευή, 14 Δεκεμβρίου 2012 9:15:12 π.μ. UTC+2, ο χρήστης Antonis 
> Kanaris έγραψε:



*That's Greek to me*

 

> Hello.I make an apk with two activities and use SharedPreferences for 
>> store user values but no workthe string url no store this is my 
>> code...Need something extra to manifest for work SharedPreferences?
>>
>> public class MainActivity extends Activity {
>>
>> @Override
>> public void onCreate(Bundle savedInstanceState) {
>> super.onCreate(savedInstanceState);
>> setContentView(R.layout.activity_main);
>> 
>>
>>
>> if (savedInstanceState != null)
>> {
>>   String strValue = savedInstanceState.getString("Url");
>>   if (strValue != null)
>>   {
>>   TextView text = (TextView) findViewById(R.id.text);
>>   
>>   //Sets the new text to TextView (runtime click event)
>>   text.setText(strValue);
>>   }
>> }
>> 
>> }
>> 
>> public void Save(View view) {
>> 
>>  SharedPreferences preferences = getPreferences(MODE_PRIVATE);
>>   SharedPreferences.Editor editor = preferences.edit();  // Put 
>> the values from the UI
>>   
>>   EditText txtUrl = (EditText)findViewById(R.id.txtUrl);
>>   String strUrl = txtUrl.getText().toString();
>>   
>>   
>>   
>>   editor.putString("Url", strUrl); // value to store
>> 
>>   // Commit to storage
>>   editor.commit();
>> 
>> Intent myIntent = new Intent(view.getContext(), Activity2.class);
>> startActivityForResult(myIntent, 0);
>> }
>>
>>
>> public class Activity2 extends Activity {
>>
>> /** Called when the activity is first created. */
>> public void onCreate(Bundle savedInstanceState) {
>> super.onCreate(savedInstanceState);
>> setContentView(R.layout.activity2);
>>
>> if (savedInstanceState != null)
>> {
>>   String strValue = savedInstanceState.getString("Url");
>>   if (strValue != null)
>>   {
>>   TextView text = (TextView) findViewById(R.id.texturl);
>>   
>>   //Sets the new text to TextView (runtime click event)
>>   text.setText(strValue);
>>   }
>> }
>>  
>> }
>> 
>> public void Setup(View view) {
>> Intent intent = new Intent();
>> setResult(RESULT_OK, intent);
>> finish();
>> }
>>
>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Re: [android-developers] Re: SharedPreferences no work

2012-12-14 Thread laxman k
public boolean save(String strurl ,Context context)
{
pref= context.getSharedPreferences("MyPref",Context.MODE_PRIVATE);
editor = pref.edit();
editor.putBoolean("URL", strurl);
editor.commit();
return true;
}

<---saving value>

save(strurl,getApplicationContext());

<--geting values--->
url=getURL(getApplicationContext());


public String GetURL(Context context)
{
pref= context.getSharedPreferences("MyPref",Context.MODE_PRIVATE);
String url=pref.getString("URL", null);
return url;
}

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Re: SharedPreferences no work

2012-12-14 Thread Antonis Kanaris


Τη Παρασκευή, 14 Δεκεμβρίου 2012 9:15:12 π.μ. UTC+2, ο χρήστης Antonis 
Kanaris έγραψε:
>
> Hello.I make an apk with two activities and use SharedPreferences for 
> store user values but no workthe string url no store this is my 
> code...Need something extra to manifest for work SharedPreferences?
>
> public class MainActivity extends Activity {
>
> @Override
> public void onCreate(Bundle savedInstanceState) {
> super.onCreate(savedInstanceState);
> setContentView(R.layout.activity_main);
> 
>
>
> if (savedInstanceState != null)
> {
>   String strValue = savedInstanceState.getString("Url");
>   if (strValue != null)
>   {
>   TextView text = (TextView) findViewById(R.id.text);
>   
>   //Sets the new text to TextView (runtime click event)
>   text.setText(strValue);
>   }
> }
> 
> }
> 
> public void Save(View view) {
> 
>  SharedPreferences preferences = getPreferences(MODE_PRIVATE);
>   SharedPreferences.Editor editor = preferences.edit();  // Put 
> the values from the UI
>   
>   EditText txtUrl = (EditText)findViewById(R.id.txtUrl);
>   String strUrl = txtUrl.getText().toString();
>   
>   
>   
>   editor.putString("Url", strUrl); // value to store
> 
>   // Commit to storage
>   editor.commit();
> 
> Intent myIntent = new Intent(view.getContext(), Activity2.class);
> startActivityForResult(myIntent, 0);
> }
>
>
> public class Activity2 extends Activity {
>
> /** Called when the activity is first created. */
> public void onCreate(Bundle savedInstanceState) {
> super.onCreate(savedInstanceState);
> setContentView(R.layout.activity2);
>
> if (savedInstanceState != null)
> {
>   String strValue = savedInstanceState.getString("Url");
>   if (strValue != null)
>   {
>   TextView text = (TextView) findViewById(R.id.texturl);
>   
>   //Sets the new text to TextView (runtime click event)
>   text.setText(strValue);
>   }
> }
>  
> }
> 
> public void Setup(View view) {
> Intent intent = new Intent();
> setResult(RESULT_OK, intent);
> finish();
> }
>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Re: SharedPreferences no work

2012-12-14 Thread skink


Antonis Kanaris wrote:
> Hello.I make an apk with two activities and use SharedPreferences for store
> user values but no work

"but no work..." - you are extremely verbose in describing your
problem

pskink

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en