android - Intent getStringExtra 返回 null

标签 android android-intent

我知道这个问题已经被问了很多,但我不知道我哪里错了..

所以我通过一个 Activity 发送了一些数据并从另一个 Activity 中检索它。

第一个 Activity

Timber.i("Photo img : %s", posterUrl);
    String url = AppConstants.IMAGE_BASE_URL+ 
    AppConstants.POSTER_SIZE_ORIGINAL+ posterUrl;
    Intent i = new Intent(this, ImageFullActivity.class);
    i.putExtra(AppConstants.IMAGE_URL, url);
    startActivity(i);

接收 Activity

Intent i = new Intent();
String imageUrl = i.getStringExtra(AppConstants.IMAGE_URL);    
Timber.i("GOt image url %s", imageUrl);
Picasso.with(this)
      .load(imageUrl)
      .into(image);

然后我检查了。我没有通过附加功能传递空值。 posterUrl 是一个有效的字符串。

最佳答案

您需要使用getIntent() 来获取启动下一个 Activity 的intent 实例

 getIntent().getStringExtra

而不是创建一个新的空的

//Intent i = new Intent(); remove

Intent i = getIntent(); // or do this

关于android - Intent getStringExtra 返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48036661/

相关文章:

android - 在Jquery Mobile中的一个页面中包含几个页面

java - 日历 View Android 帮助

android - 在 Intent-Filter 中使用多个 Action 时的默认设置

android - 如何使用 robolectric 用额外的数据测试开始的 Intent

java - 尝试从 Google 相册应用中选择照片时出现 IllegalStateException

android - 我可以使用 ACTION_VIEW 查看我下载的 JPG 吗?

android - Firebase 返回 null 但数据存在

android - 将库导入 Android Studio 遇到很多麻烦

java - 我的程序在 ListView 中第二次单击时崩溃

android - 如何在 Android 设备中检测来电?