java - Intent 消息传递困惑

标签 java android android-intent message

我对 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/

相关文章:

java - 从 Java 访问 HTML DOM 元素

Android 构建和安装错误 : INSTALL_PARSE_FAILED_NOT_APK

重叠 VideoView 的 Android 布局排序无法正常工作

android - 单个实例 : Launch Mode of Launcher Activity

Android back stack - 返回到back stack中的某个activity

java - Android Intent 选择设置默认应用

java - Office365 API获取ReferenceAttachment的内容

带有 EditText 的 Java/Android 对话框 - 对字符串进行 boolean 检查

java - 如何在java中连接sql数据库时制作加载屏幕

java - Android - 打开图库中的文件夹