Android activity Switching

Source: Internet
Author: User

In Android, each activity generally describes all the pictures on a screen (except for window-level activity). Therefore, two screens on a mobile phone are usually used (the whole screen is accurate) activity switching is involved.
Assume that there are two activities, activity01 and activity02. Now there is a button in the activity01 page. After clicking it, it switches to activity02. during activity switching, activity01 passes a parameter to activity02. (intent can be used when switching activity and data can be transferred .)

How can this problem be solved? The general idea is:

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

2. Add a listener to the activity01 trigger.

3. In the listener interface implementation, set an intent so that the intent can bind activity01 and activity02 and put the value to be transmitted through putextra into the intent object for storage.

3. At the end of the listener interface implementation, start and call the intent object through activity01, and switch to activity02 through the call.

4. In activity02, use getintent to obtain the intent object instance that has been started in context switching.

5. Use getstringextra to obtain the previous putextra value through the obtained intent object instance.

Of course, if you know more about intent later, you need to select a more suitable function to store and obtain data based on the actual situation.

The following is an implementation Demonstration:

The following code is attached:

In activity01:

Button. setonclicklistener (New button. onclicklistener () {// view is more accurate. onclicklistener public void onclick (view v) {/* Create an intent object */intent = new intent (); intent. putextra ("name", "Leipei");/* specifies the intent class */intent. setclass (activity01.this, activity02.class);/* start a new activity */activity01.this. startactivity (intent);/* close the current activity */activity01.this. finish ();}});

In activity02:

String name = intent. getstringextra ("name"); textview2.settext ("the value passed by activity01 is:" + name );
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.