The code below is the source code for the third and fourth activity.The third activity receives a user input and performs a mathematical operation on it. Then both the original and processed values are send to the fourth activity where it needs to be displayed. I am not quite familiar with the use of intents. Can somebody check my code? It's not working.
Third Activity
public class Third extends Activity {
double x=0, val1=0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.third);
final EditText et;
final Button b;
et = (EditText) findViewById(R.id.editText1);
b = (Button) findViewById(R.id.button1);
b.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Third.this, Fourth.class);
intent.putExtra("thetext", et.getText().toString());
startActivity(intent);
x=Double.parseDouble(et.getText().toString());
val1=(x*.04);
Intent in1 = new Intent(Third.this, Fourth.class);
in1.putExtra("thevalue1",val1);
startActivity(in1);
}
});
}
}
Fourth Activity:
public class Fourth extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.fourth);
TextView tv = (TextView) findViewById(R.id.textView1);
tv.setText(getIntent().getExtras().getString("thetext"));
TextView wt1=(TextView) findViewById(R.id.textView12);
wt1.setText(getIntent().getExtras().getDouble("thevalue1"));
}
}