Hello.I make an apk with two activities and use SharedPreferences for store
user values but no work....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 [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-developers?hl=en