How do I get extra data from intent on Android?

后端 未结 16 2277
清歌不尽
清歌不尽 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 11:41

    Getting Different Types of Extra from Intent

    To access data from Intent you should know two things.

    • KEY
    • DataType of your data.

    There are different methods in Intent class to extract different kind of data types. It looks like this

    getIntent().XXXX(KEY) or intent.XXX(KEY);


    So if you know the datatype of your varibale which you set in otherActivity you can use the respective method.

    Example to retrieve String in your Activity from Intent

    String profileName = getIntent().getStringExtra("SomeKey");
    

    List of different variants of methods for different dataType

    You can see the list of available methods in Official Documentation of Intent.

提交回复
热议问题