我有一个应用程序,它需要一个字符串来计算一些算法。它工作正常。现在我试图从主要活动中调用此活动,因此主要活动需要用户输入来覆盖第二个活动中的字符串。我在主要活动中有一个可编辑字段。我无法将主要活动的值传递给第二个活动。我怎样才能做到这一点?我的主要活动代码如下所示
public void onClick(View view){
switch (view.getid())
case R.id.calculate:
setname= insertname.getText.toString(); //insertname is the Editablefield
Intent i = new Intent(this, themain.class);
i.putExtra("Name",insertname); //
startActivityForresult(i,1);
}
protected void onActivityResult(int requestCode, int resultCode,Intent data) {
super.onactivityresult(requestcode resultcode data);
switch (requestcode ){
case 1:
//return result form activity 2
}
}
// Code for second activity is something like this:
public void onClick(View view) {
switch (view.getid()) {
case R.id.calculate:
break;
/*
* this bit of code takes a string and gets data for this user and
* returns it in an array. I am trying to overwrite this string
*/
}
}