android intent 传参应注意的
例如如下代码:
1 button = (Button) this.findViewById(R.id.search_button); 2 textView = (TextView) this.findViewById(R.id.text_search); 3 button.setOnClickListener(new OnClickListener() { 4 5 @Override 6 public void onClick(View v) { 7 Intent intent = new Intent(TestActivity.this,Top3ProduceActivity.class); 8 intent.putExtra("result_text",textView.getText()); 9 startActivity(intent); 10 } 11 });
当Test2Activity 通过getIntent(),取跳转中的数据,将会报错,textView.getText()不是string 类型数据
//intent.putExtra("result_text", textView.getText()); intent.putExtra("result_text",""+ textView.getText());