How do I get extra data from intent on Android?

后端 未结 16 2273
清歌不尽
清歌不尽 2020-11-21 11:01

How can I send data from one activity (intent) to another?

I use this code to send data:

Intent i=new Intent(context,SendMessage.class);
i.putExtra(\         


        
16条回答
  •  渐次进展
    2020-11-21 12:01

    If used in a FragmentActivity, try this:

    The first page extends FragmentActivity

    Intent Tabdetail = new Intent(getApplicationContext(), ReceivePage.class);
    Tabdetail.putExtra("Marker", marker.getTitle().toString());
    startActivity(Tabdetail);
    

    In the fragment, you just need to call getActivity() first,

    The second page extends Fragment:

    String receive = getActivity().getIntent().getExtras().getString("name");
    

提交回复
热议问题