I'm trying to start a new activity in my android app, and I'm trying to pass a simple string from the first activity to the second activity. I want the string to display in a textview for now in the second activity, but it just won't work. What am I doing wrong?
The initial activity:
package com.amritayalur.mypowerschool;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.method.ScrollingMovementMethod;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MyPowerSchoolActivity extends Activity {
Button buttonSubmit;
TextView TextViewTitle;
TextView TextViewDesc;
EditText EditTextURL;
String url = "";
String str;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
buttonSubmit = (Button) findViewById(R.id.buttonSubmit);
TextViewTitle = (TextView) findViewById(R.id.TextViewTitle);
TextViewDesc = (TextView) findViewById(R.id.TextViewDesc);
EditTextURL = (EditText) findViewById(R.id.EditTextURL);
//Start TextView
TextViewTitle.setText("MyPowerSchool");
//button listener
buttonSubmit.setOnClickListener(new View.OnClickListener() {
String url = EditTextURL.getText().toString();
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent i = new Intent( MyPowerSchoolActivity.this,
creds.class);
i.putExtra("pschoolurl", url);
final int result = 1;
startActivityForResult(i, result);
}
});
}
}
The second activity:
package com.amritayalur.mypowerschool;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Gravity;
import android.webkit.WebView;
import android.widget.Toast;
import android.widget.TextView;
public class creds extends Activity {
String test;
TextView TextViewTest;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.second);
Intent intent = getIntent();
String test = intent.getExtras().getString("pschoolurl");
TextViewTest = (TextView) findViewById(R.id.TextViewTest);
TextViewTest.setText(test);
}
}
I know the textview displays properly in the second activity; it works with any dummy text, just not the variable.