I've created three activities the first one is the Main_Activity, the second is called new_button, and the third is called general_button. The main_activity contains the other two activities, with the button (New) for the new_button activity, and the button (general) for the general_button activity. the new_button activity contains one EditText and one button called done_button. the general_button activity contains only one TextView. I used Intent to transfer the written data in the EditText from the new_button activity to the TextView in the general_button activity with the following code:
new_button(Activity):
package com.tarek.topshine;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class new_button extends Activity {
Button done_button;
String text;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.new_button);
addListenerOnButton();}
public void addListenerOnButton() {
done_button = (Button) findViewById(R.id.done_button);
done_button.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
EditText editText = (EditText)findViewById(R.id.editText1);
String text = editText.getText().toString();
Intent myIntent = new Intent(view.getContext(),general_button.class);
myIntent.putExtra("mytext",text);
startActivity(myIntent);
}
});
}
general_button(Activity):
package com.tarek.topshine;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class general_button extends Activity {
TextView mTextview;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.general_button);
mTextview = (TextView)findViewById(R.id.textView1);
mTextview.setText(getIntent().getStringExtra("mytext"));
}
}
Now the problem I'm facing is that I can't save the intented information from the new_button activity to the general_button activity. for example: I need to open the general_button activity later from the main_activity and see the edited information. I read on the internet that I can use the onSavedInstanceState method, but I couldn't figure it out :(
Am I doing something wrong? and if I am, how can I solve this ?!
Thanks for the help :)