我知道这个问题已经被问了很多,但我不知道我哪里错了..
所以我通过一个 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/