Summary of objects passed by Android Intent

Source: Internet
Author: User
Tags set set

Effect:

If you want to see an instance, you can read an article earlier.

Android ViewPager Fragment implementation Tab

Some key code:

Public class SerializeActivity extends Activity implements Serializable {Button btnlist, btnParcelable, btnSerialze; private final String TAG = "SerializeActivity"; public final static String LIST_KEY = "ArrayList "; public final static String PAR_KEY = "parcelable"; public final static String SER_KEY = "serializable"; private static final long serialVersionUID = 1L; private ArrayList
 
  
M_list; @ Overrideprotected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_serialize); initView (); initlist ();}/** initialize view */public void initView () {btnlist = (Button) findViewById (R. id. btnlist); btnParcelable = (Button) findViewById (R. id. btnParcelable); btnSerialze = (Button) findViewById (R. id. btnSerialze); btnlist. setOnClickListener (btnlistener); btnParcelable. setOnClickListener (btnlistener); btnSerialze. setOnClickListener (btnlistener);} public void initlist () {m_list = new ArrayList
  
   
(); M_list.add ("www.88ios.com"); m_list.add ("Android mobile development"); m_list.add ("IOS development entry ");} /** button click event */OnClickListener btnlistener = new OnClickListener () {public void onClick (View v) {switch (v. getId () {case R. id. btnlist: intentList (); break; case R. id. btnParcelable: intentParcelabe (); break; case R. id. btnSerialze: intentShowSer (); break ;}};/***/public void intentList () {Intent list_intent = new Intent (); list_intent.putStringArrayListExtra (LIST_KEY, m_list ); list_intent.setClass (SerializeActivity. this, ShowInfo. class); startActivity (list_intent);}/***/public void intentParcelabe () {Student m_Student = new Student (); m_Student.setName ("88ios.com"); m_Student.setAge (25 ); m_Student.setSex ("male"); Intent p_Intent = new Intent (SerializeActivity. this, ShowParcelabe. class); Bundle mBundle = new Bundle (); mBundle. putParcelable (PAR_KEY, m_Student); p_Intent.putExtras (mBundle); startActivity (p_Intent);}/***/public void intentShowSer () {final SerializableMap myMap = new SerializableMap (); List
   
    
> List = new ArrayList
    
     
> (); Map
     
      
Maplist; Map
      
        ParamMap4 = new HashMap
       
         (); ParamMap4.put ("name", "Hong shengpeng"); paramMap4.put ("website", "www.88ios.com"); paramMap4.put ("address", "Guangzhou"); myMap. setMap (paramMap4); SerializableMap serializableMap = (SerializableMap) myMap; maplist = serializableMap. getMap (); list. add (maplist); Intent mIntent = new Intent (SerializeActivity. this, ShowSer. class); Bundle mBundle = new Bundle (); mBundle. putSerializable ("map", (Serializable) myMap); // mBundle. putSerializable ("map", (Serializable) list); mIntent. putExtras (mBundle); startActivity (mIntent );}}
       
      
     
    
   
  
 
ShowInfo. java

public class ShowInfo extends Activity {private Intent list_intent;private ArrayList
 
   m_arrayList;private TextView textview;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_show_info);textview = (TextView) findViewById(R.id.textview);StringBuffer sb = new StringBuffer();list_intent = getIntent();m_arrayList = list_intent.getExtras().getStringArrayList(SerializeActivity.LIST_KEY);m_arrayList.get(0);sb.append(m_arrayList.get(0) + " \n" + m_arrayList.get(1) + "\n"+ m_arrayList.get(2));textview.setText(sb);}}
 

ShowParcelabe. java

Public class ShowParcelabe extends Activity {private TextView textview; @ Overrideprotected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_show_parcelabe); textview = (TextView) findViewById (R. id. textview); Student p_student = (Student) getIntent (). getParcelableExtra (SerializeActivity. PAR_KEY); textview. setText ("name:" + p_student.getName () + "\ n" + "Age:" + p_student.getAge () + "\ n" + "Gender:" + p_student.getSex () + "\ n" + "class:" + p_student.getClass ());}}

Show.java

public class ShowSer extends Activity {private TextView textview;StringBuilder sb = new StringBuilder();@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_show_ser);textview = (TextView)findViewById(R.id.textview);  Map
 
   maplist;Bundle bundle = getIntent().getExtras();SerializableMap serializableMap = (SerializableMap) bundle.get("map");maplist = serializableMap.getMap();/*for (String k : maplist.keySet()) {Toast.makeText(this, "" + maplist.get(k), Toast.LENGTH_SHORT).show();}        */Set set = maplist.entrySet();Iterator it = set.iterator();while (it.hasNext()) {Map.Entry entry = (Map.Entry) it.next();String key = (String) entry.getKey();String valu = (String) entry.getValue();sb.append(key+"  "+valu+"\n");}textview.setText(sb);   }}
 



Reprinted please keep Link

Http://hongshengpeng.com/article/show/271.aspx


Source code download


QQ

Communication Group: 154950206 group verification: 88ios

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.