Android Activity switch

Source: Internet
Author: User

Transferred from: http://www.cnblogs.com/leipei2352/archive/2011/08/09/2132096.html

Each activity in Android typically describes all the screens on a screen (except for window-level activity), so switching between the two interface (which is exactly the whole screen) of the phone screen involves switching between the activity.
Assuming there are two activity, Activity01 and Activity02, there is now a button on the ACTIVITY01 page that switches to Activity02 after the click. And when the activity switches, Activity01 passed a parameter to Activity02. (Intent can be used when switching activity and can pass data.)

How do you do it? The general idea is:

1. Set a trigger space in Activity01 and add a trigger

2. Add listener to the ACTIVITY01 trigger

3. In the Listener interface implementation, set up a intent that allows the intent to bind Activity01 and Activity02 and store the Putextra object by intent the value to be transferred

The end of the 3.listener interface implementation, the intent object is invoked via Activity01, and is switched to ACTIVITY02

4. In Activity02, use getintent to get the instance of the intent object in the context switch that makes itself bootable

5. With the intent object instance obtained, use the Getstringextra to get the value of the previous Putextra.

Of course, if you know more about intent in the future, you need to pick a more appropriate function for storing data and getting the data according to the actual situation.

The following is a demonstration of the implementation:

Finally, attach the key part code:

In Activity01:

Button.setonclicklistener (new Button.onclicklistener () {///More accurate point should be View.onclicklistener    void OnClick ( View v)    {        /* Create a new Intent object *        /New Intent ();        Intent.putextra ("name",/* Specifies intent to start the class */Intent.setclass (Activity01.  This, Activity02. / * Start a new activity */ACTIVITY01. / * Close the current Activity */ACTIVITY01. this.finish ();}});         

In Activity02:

        String Name=intent.getstringextra ("name");        Textview2.settext ("Activity01 passed the value is:" +name); 

Android Activity switch

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.