我是安卓初学者。我想将结果从 FirstActivity 传递给 SecondActivity,如下所示。如何删除意图额外的结果?或者以任何方式将结果传递给 SecondActivity 并显示在 TextView 上?(我犯了一个错误并替换,我的主要问题是如何删除结果,因为我想在其中设置另一个新结果。)
第一活动.java
public class FirstActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//code...
try {
myDbHelper.createDatabase();
}
catch (IOException ioe) {
Log.d("Error","Error while createing Database");
ioe.printStackTrace();
throw new Error("Unable to create database");
}
try {
myDbHelper.openDataBase();
}
catch(SQLException sqle){
Log.d("Error","Error while Opening Database");
sqle.printStackTrace();
throw sqle;
}
send.setOnClickListener( new View.OnClickListener() {
public void onClick(View v) {
showResult();
}
});
}
private void showResult() {
//...code
//checking for slection
results = queryData(table, type);
Intent intent = new Intent(this,SecondActivity.class);
intent.putExtra("results", results);
startActivity(intent);
}
public String queryData(String table, String type){
//...
//do somthing to get result
return result;
}
}
SecondActivity.java
public class SecondActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.result_item);
TextView tv;
tv = (TextView)findViewById(R.id.tv);
Bundle extras=getIntent().getExtras();
String value1=extras.getString("results");
tv.setText("Result\n" + value1);
}
}