[英]Android put extra doesn't send extras to another activity
I try to send some values to another activity. 我尝试将一些值发送到另一个活动。
recyclerView.addOnItemTouchListener(new RecyclerTouchListener(getApplicationContext(), recyclerView, new RecyclerTouchListener.ClickListener() {
@Override
public void onClick(View view, int position) {
Intent intent = new Intent(GroupsMain.this, AboutGroup.class);
intent.putExtra("groupName", "Hello");
startActivity(intent);
}
@Override
public void onLongClick(View view, int position) {
}
}));
And so on AboutGroup activity I try to get extra. 等等AboutGroup活动,我尝试获得更多。 1 way:
1种方式:
Bundle extras = getIntent().getExtras();
String name = extras.getString("groupName");
and second way: 第二种方式:
Intent intent = new Intent();
String name = intent.getStringExtra("groupName");
But nothing works for me. 但是对我来说没有任何用。 On AboutGroup activity i get empty string.
在AboutGroup活动中,我得到空字符串。 Please help me fix this problem.
请帮助我解决此问题。
try this 尝试这个
Send: 发送:
Intent intent = new Intent(MainActivity.this, Main2Activity.class);
intent.putExtra("groupName", "Hello Anna");
startActivity(intent);
get extra: 得到更多:
String name = getIntent().getStringExtra("groupName");
myTextview.setText(name);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.