I have a problem in following code:
Activity---HelloAndroid
......
btnSpp.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
Intent i=new Intent();
i.setClass(HelloAndroid.this,
SharePreferencePage.class);
startActivityForResult(i,REQUEST_TYPE_B);
}
}); // Jump to another input screen
.......
protected void onActivityResult(int requestCode, int
resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
......
TextView txt = (TextView)findViewById(R.id.txt);
SharedPreferences
sp=getSharedPreferences("Text",0);
android.util.Log.d("HA","----
>"+sp.getString("Text", "none"));
txt.setText(sp.getString("Text",
"null"));
......
} //Accept the return value from sharedPreferences
Activity--SharePreferencePage
......
btn.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
result=et.getText().toString();
SharedPreferences
sp=getSharedPreferences("Text",0);
SharedPreferences.Editor edit=sp.edit();
edit.putString("Text", result);
try{
boolean b=edit.commit();
setResult(Activity.RESULT_OK);
}catch(Exception e){
android.util.Log.d("SPP","---->expetion:"+e.toString());
}
finish();
}
});
.............
=====================================================
The problem is in "boolean b=edit.commit();" , it's always false. But
the value is set successfully. And can be get from SharedPreferences
sp=getSharedPreferences("Text",0);
In Spec, commit() return false mean write flase. Why in this case it
will return false?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---