How do I get extra data from intent on Android?

后端 未结 16 2295
清歌不尽
清歌不尽 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:42

    This is for adapter , for activity you just need to change mContext to your Activty name and for fragment you need to change mContext to getActivity()

     public static ArrayList tags_array ;// static array list if you want to pass array data
    
          public void sendDataBundle(){
                tags_array = new ArrayList();
                tags_array.add("hashtag");//few array data
                tags_array.add("selling");
                tags_array.add("cityname");
                tags_array.add("more");
                tags_array.add("mobile");
                tags_array.add("android");
                tags_array.add("dress");
                Intent su = new Intent(mContext, ViewItemActivity.class);
                Bundle bun1 = new Bundle();
                bun1.putString("product_title","My Product Titile");
                bun1.putString("product_description", "My Product Discription");
                bun1.putString("category", "Product Category");
                bun1.putStringArrayList("hashtag", tags_array);//to pass array list 
                su.putExtras(bun1);
                mContext.startActivity(su);
            }
    

提交回复
热议问题