Reputation: 1103
I have one form in which user must write some info and send to mysql database. What I trying now is to make new activity which after the user submit the form to load and display what he just submitted - an Summary page.
In this Activity I get all the info from previous activity and user send data to DB. Then I try to pass info to Summary.class
btnFinish = (Button) findViewById(R.id.btnFinish);
btnFinish.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Bundle extras = getIntent().getExtras();
if (extras != null) {
Name = getIntent().getExtras().getString("Name");
Email = getIntent().getExtras().getString("Email");
}
new SummaryAsyncTask().execute((Void) null);
Intent newActivity = new Intent(TableInformation.this, Summary.class);
newActivity.putExtra("Name", Name);
newActivity.putExtra("Email", Email);
Log.d("Information to summary", Name + " " + Email);
startActivity(new Intent(Information.this, Summary.class));
}
And this is what I have currently in Summary.class
String getName;
String getEmail;
TextView nameOfPerson, emailOfPerson;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.summary);
Bundle extras = getIntent().getExtras();
if (extras != null) {
getName = getIntent().getExtras().getString("Name");
getEmail = getIntent().getExtras().getString("Email");
}
((TextView)findViewById(R.id.nameOfPerson)).setText(getName+"");
((TextView)findViewById(R.id.emailOfPerson)).setText(getEmail+"");
}
And the summary.xml
contain
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/nameOfPerson"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginTop="75dp"
android:text=""
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/emailOfPerson"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:text=""
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
The result now is NULL
on both textview
. Can anyone help whit this?
Upvotes: 0
Views: 53
Reputation: 89
The problem is You don't set bundle to activity on first activity before calling start activity
By the way initialize bundle variable like
Bundle extrabundle = new Bundle();
Upvotes: 1
Reputation: 1371
You are creating a new intent while starting the activity. It seems like a error.
Instead of
Intent newActivity = new Intent(TableInformation.this, Summary.class);
newActivity.putExtra("Name", Name);
newActivity.putExtra("Email", Email);
Log.d("Information to summary", Name + " " + Email);
startActivity(new Intent(Information.this, Summary.class));
do this
Intent newActivity = new Intent(TableInformation.this, Summary.class);
newActivity.putExtra("Name", Name);
newActivity.putExtra("Email", Email);
Log.d("Information to summary", Name + " " + Email);
startActivity(newActivity);
If you have any query please comment.
Upvotes: 1