I'm learning Android and I didn't find an answer on the web. I want to save a string from an EditText
on my MainActivity
to restore it on my third Activity
-> Activity3
I want this string to be displayed on a TextView
of this Activity
.
public class MainActivity extends Activity {
private EditText nomPrenom;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
nomPrenom = (EditText) findViewById(R.id.nomPrenom);
...................}
in my activity_main.xml :
android:id="@+id/nomPrenom"
android:text="@string/nomPrenom"
and
public class Activity3 extends ListActivity {
private TextView yourName;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_activity3);
yourName = (TextView) findViewById(R.id.nomPrenom);
yourName.setText("take the name of activity 1 here"); //<-- this line causes crash !!
..................}
here is activity3.xml
android:id="@+id/yourName"
android:text="@string/nomPrenom"
How can I do that ?