为什么这个值没有出现在咨询医生血症的第二个活动中?我认为代码已经正确了。但它显示为null。
resultAnaemia
if(symptom16.equals("Yes"))
{
weight=0.11;
newWeight = 0.0 * 0.15; //cf disease = 0.6, [min=0.15]
String cf = Double.toString(newWeight);
Intent intent = new Intent(resultAnemia.this, consultDoctorAnaemia.class);
intent.putExtra("cfDiseases", cf);
startActivity(intent);
}
consultDoctorAnaemia
TextView textView = (TextView) findViewById(R.id.textCF);
//get passed intent
Intent intent = getIntent();
if(null != intent)
{
//get cf value from intent
String cf = intent.getStringExtra("cfDiseases");
textView.setText("Certainty value : " + cf);
}
答案 0 :(得分:1)
Bundle extras = getIntent().getExtras();
if (extras != null) {
String Diseases = extras.getString("cfDiseases");
}
答案 1 :(得分:0)
您需要参加consultDoctorAnaemia活动:
Bundle bundle = getIntent().getExtras();
String value2 = bundle.getString("cfDiseases");
答案 2 :(得分:0)
在第一项活动中尝试此操作:
// do your intent setup somewhere and then setup bundle
Bundle info = new Bundle();
info.putString("cfDiseases", cf);
intent.putExtras(info);
startActivity(intent);
在新活动中: Bundle info = new Bundle(); info = getIntent()。getExtras(); cf = info.getString(" cfDiseases");
答案 3 :(得分:0)
你也可以像这样传递价值
声明你的字符串全局和静态例如
在此类中声明变量
A类
public class A extends Activity{
static String cf = "abcde";
}
此B类中的访问变量
B类
public class B extends Activity{
String Temp;
//you can get variable like this
Temp=A.cf ;
Toast.makeText(B.this, "Temp = "+Temp, Toast.LENGTH_SHORT).show();
}