Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //ACTIVITY 1
- package com.example.test;
- import android.os.Bundle;
- import android.app.Activity;
- import android.content.Intent;
- import android.content.SharedPreferences;
- import android.view.View;
- import android.widget.Button;
- import android.widget.TextView;
- public class MainActivity extends Activity {
- TextView t1,t;
- SharedPreferences myPrefs;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- t=(TextView) findViewById(R.id.textView1);
- t1=(TextView) findViewById(R.id.textView2);
- Button b=(Button) findViewById(R.id.button1);
- b.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- // TODO Auto-generated method stub
- // Intent i = new Intent(MainActivity.this, New.class);
- // startActivityForResult(i, 1);
- startActivity(new Intent(MainActivity.this,New.class));
- }
- });
- }
- @Override
- protected void onResume() {
- super.onResume();
- myPrefs = this.getSharedPreferences("myPrefs", MODE_WORLD_READABLE);
- String prefName = myPrefs.getString("key", "nothing");
- t.setText(prefName);
- }
- @Override
- protected void onActivityResult(int requestCode, int resultCode, Intent data) {
- // TODO Auto-generated method stub
- if (requestCode == 1) {
- if(resultCode == RESULT_OK){
- String rem=data.getStringExtra("edittextvalue");
- t1.setText(rem);
- }
- }
- }
- }
- //ACTIVITY 2
- package com.example.test;
- import android.app.Activity;
- import android.content.Intent;
- import android.content.SharedPreferences;
- import android.os.Bundle;
- import android.widget.EditText;
- public class New extends Activity {
- EditText e;
- SharedPreferences myPrefs;
- SharedPreferences.Editor prefsEditor;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- // TODO Auto-generated method stub
- super.onCreate(savedInstanceState);
- setContentView(R.layout.newx);
- e=(EditText) findViewById(R.id.editText1);
- myPrefs = this.getSharedPreferences("myPrefs", MODE_WORLD_READABLE);
- prefsEditor = myPrefs.edit();
- }
- @Override
- public void onBackPressed() {
- // TODO Auto-generated method stub
- String text = e.getText().toString();
- prefsEditor.putString("key", text);
- prefsEditor.commit();
- // Intent intent = new Intent();
- // intent.putExtra("edittextvalue",e.getText().toString());
- // setResult(RESULT_OK, intent);
- // finish();
- super.onBackPressed();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement