我想在两个 Activity 之间传递一个字符串,但是当我收到该字符串时,我得到一个空值。 我在其他 Activity 中使用相同的代码并且运行良好。有什么建议吗?
第一个 Activity :
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_post);
Glide.with(PostCarrete.this).load(foto)
.centerCrop()
.into(imagen);
next = (ImageView) findViewById(R.id.next) ;
next.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(PostCarrete.this, Compartir.class);
intent.putExtra("foton",foto);
startActivity(intent);
}
});
}
第二个 Activity :
Bundle bundle = getIntent().getExtras();
foto = bundle.getString("foton");
这里bundle的值为null,所以foto也是
最佳答案
我认为应该是:
String foto = getIntent().getStringExtra("foton");
因为你也作为额外发送
关于android - bundle.getString() 返回空值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39353426/