简体   繁体   English

Android Put Extra不会将Extra发送给其他活动

[英]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.

相关问题 Android:将Extras(ArrayList)发送到任何活动 - Android: Send Extras (ArrayList) to any Activity 切换活动并将字符串额外发送给另一个活动 - switch activity and send string as an extra to another activity Android-检查数组是否具有此值,获取位置并发送多余的意图到下一个活动片段 - Android - Check whether the array has this value , get the position and send intent put extra to next activity fragment 将Android启动活动更改为另一个活动= app无法加载 - Changing Android launch activity to another activity = app doesn't load 无论如何,是否有意在没有开始活动的情况下额外发送意图数据? - Is there anyway to send data in an intent put extra without starting an activity? 从选项卡活动 android 传递附加信息 - Passing extras from tab activity android Android,将Extras从活动传递到片段活动再到片段 - Android, passing Extras from activity, to fragment activity, to fragment extras(通知文本)没有通过 - extras(notification text) doesn't get passed 如何在Android中将哈希映射数组从一个活动发送到另一个活动 - How to send array of Hashmap from one activity to another activity in android Android Manifest无法启动活动 - Android Manifest doesn't start activity
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM