Intent (1, passing parameters)

Source: Internet
Author: User

Intent means "intention, purpose", as the information transmission medium between different components, mainly the following three:

    • Activity:startactivity () and Startactivityforresult ();
    • Service:startservice () and Bindservice ();
    • Broadcast:sendbroadcast (), Sendoderedbroadcast () and Sendstickybroadcast ();

Intent transfer parameters in different component parts, mainly related to the following categories:

    • Basic data, such as strings, integers, and so on, are as follows:
// Send Intent.putextra ("Key1", "value1"); Intent.putextra ("Key2", 2.0f); // Accept Intent Intent This  . getintent (); String value1  = Intent.getstringextra ("Key1"); float  value2   = Intent.getfloatextra ("Key2", 0);
    • Using bundles
      • Integrating objects into the Serializable interface
 Public class Implements Serializable {//can also be parcelable, similar
      • Add bundles to the intent as follows:
// Send New Bundle ();                     New User (); User.setusername ("Fredric"); User.setpassword ("Sinny"); Bundle.putserializable ( "User", user); Intent.putextras (bundle);    // Receive  This  = Intent.getextras ();         = (user) bundle.get ("User");     

    • Coercion type conversions, as in the following example:
//SendList<user> userlist =NewArraylist<user>(); for(inti = 0; I < 10; i++) {User tmp=NewUser (); Tmp.setusername ("Sinny"); Tmp.setpassword ("Fredric" +i);                    Userlist.add (TMP);} Intent.putextra ("UserList", (Serializable) userlist);//ReceiveList<user> userlist = (list<user>) Intent.getserializableextra ("UserList"); Iterator<User> iterator =Userlist.iterator ();  while(Iterator.hasnext ()) {User tmp=Iterator.next (); LOG.I (Tag_activity, Tmp.getusername ()+Tmp.getpassword ());}

Intent (1, passing parameters)

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.