我对 android 中的 Intent 和消息传递有点困惑。基本上是我当前的困境:
当用户单击一行时,例如,向用户显示一个显示动物列表的屏幕。一只老虎,有关该动物的信息将显示在下一个屏幕/Activity 上。
我已经基本完成了应用程序的框架,因此当用户从动物列表中选择时,他们将被带到 Animal Activity/类,但在这个阶段它只是一个通用的模型。
我如何告诉应用程序选择了 TIGER,并向用户显示老虎数据。到目前为止我的方法
用户单击列表中的项目并调用 Activity :
protected void onListItemClick(ListView l, View v, int position, long id){
Intent animalIntent = new Intent(this, Animal.class);
startActivity(animalIntent);
}
最佳答案
为了扩展@PhillLello,一旦使用 Intent.setExtra(),您就可以通过以下方式检索 Activity 中的值:
string animal;
Bundle extras = this.getIntent().getExtras();
if (extras != null) {
animal = extras.getString("animal");
}
关于java - Intent 消息传递困惑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5585619/