(To) summary of the basic usage of intent

Source: Internet
Author: User
Tags call back

1. No parameter for activity jump

Intent it = new intent (activity. Main. This, activity2.class );

Startactivity (it );

2. pass data to the next activity (use bundle and intent. putextras)

Intent it = new intent (activity. Main. This, activity2.class );

Bundle bundle = new bundle ();

Bundle. putstring ("name", "this is from mainactivity! ");

It. putextras (bundle); // it. putextra ("test", "shuju ");

Startactivity (it); // startactivityforresult (it, request_code );

You can use the following methods to obtain data:

Bundle bundle = getintent (). getextras ();

String name = bundle. getstring ("name ");

3. Return the result to the previous activity (use setresult to start the activity for startactivityforresult (it, request_code)

Intent intent = getintent ();

Bundle bundle2 = new bundle ();

Bundle2.putstring ("name", "this is from showmsg! ");

Intent. putextras (bundle2 );

Setresult (result_ OK, intent );

4. Call back the result processing function (onactivityresult) of the previous activity)

@ Override

Protected void onactivityresult (INT requestcode, int resultcode, intent data ){

// Todo auto-generated method stub

Super. onactivityresult (requestcode, resultcode, data );

If (requestcode = request_code ){

If (resultcode = result_canceled)

Settitle ("cancle ");

Else if (resultcode = result_ OK ){

String temp = NULL;

Bundle bundle = data. getextras ();

If (bundle! = NULL) temp = bundle. getstring ("name ");

Settitle (temp );

}

}

}

The following are some other intent usage examples (from javaeye)

Display webpage

1. Uri uri = URI. parse ("http://google.com ");

2. Intent it = new intent (intent. action_view, Uri );

3. startactivity (it );

Show Map

1. Uri uri = URI. parse ("Geo: 38.899533,-77.036476 ");

2. Intent it = new intent (intent. action_view, Uri );

3. startactivity (it );

4. // other GEO Uri? Example

5. // GEO: latitude, longpolling

6. // GEO: latitude, longpolling? Z = zoom

7. // GEO: 0, 0? Q = My + street + address

8. // GEO: 0, 0? Q = business + near + city

9. // Google. Streetview: cbll = Lat, LNG & white = 1, yaw, pitch, zoom & MZ = mapzoom

Route Planning

1. Uri uri = URI. parse ("http://maps.google.com/maps? F = D & saddr = startlat % 20 startlng & daddr = endlat % 20 endlng & HL = EN ");

2. Intent it = new intent (intent. action_view, Uri );

3. startactivity (it );

4. // Where startlat, startlng, endlat, endlng are a long with 6 decimals like: 50.123456

Call

1. // call the dialing program

2. Uri uri = URI. parse ("Tel: 0800000123 ");

3. Intent it = new intent (intent. action_dial, Uri );

4. startactivity (it );

1. // directly call

2. Uri uri = URI. parse ("Tel: 0800000123 ");

3. Intent it = new intent (intent. action_call, Uri );

4. startactivity (it );

5. // use ?, In androidmanifest. XML, add

6 .//

Send SMS/MMS

1. // call the SMS Program

2. Intent it = new intent (intent. action_view, Uri );

3. It. putextra ("sms_body", "the SMS text ");

4. It. settype ("Vnd. Android-DIR/MMS-SMS ");

5. startactivity (it );

1. // send messages

2. Uri uri = URI. parse ("smsto: // 0800000123 ");

3. Intent it = new intent (intent. action_sendto, Uri );

4. It. putextra ("sms_body", "the SMS text ");

5. startactivity (it );

1. // send MMS

2. Uri uri = URI. parse ("content: // media/external/images/Media/23 ");

3. Intent it = new intent (intent. action_send );

4. It. putextra ("sms_body", "some text ");

5. It. putextra (intent. extra_stream, Uri );

6. It. settype ("image/PNG ");

7. startactivity (it );

Send email

1. Uri uri = URI. parse ("mailto: [email protected]");

2. Intent it = new intent (intent. action_sendto, Uri );

3. startactivity (it );

1. Intent it = new intent (intent. action_send );

2. it. putextra (intent. extra_email, "[email protected]");

3. It. putextra (intent. extra_text, "the email body text ");

4. It. settype ("text/plain ");

5. startactivity (intent. createchooser (IT, "Choose email client "));

1. Intent it = new intent (intent. action_send );

2. String [] TOS = {"[email protected]"};

3. String [] CCS = {"[email protected]"};

4. It. putextra (intent. extra_email, TOS );

5. It. putextra (intent. extra_cc, CCS );

6. It. putextra (intent. extra_text, "the email body text ");

7. It. putextra (intent. extra_subject, "the email subject text ");

8. It. settype ("message/rfc822 ");

9. startactivity (intent. createchooser (IT, "Choose email client "));

1. // transfer the attachment

2. Intent it = new intent (intent. action_send );

3. It. putextra (intent. extra_subject, "the email subject text ");

4. It. putextra (intent. extra_stream, "file: // sdcard/mysong.mp3 ");

5. sendintent. settype ("audio/MP3 ");

6. startactivity (intent. createchooser (IT, "Choose email client "));

Play multimedia

Uri uri = URI. parse ("file: // sdcard/song.mp3 ");

Intent it = new intent (intent. action_view, Uri );

It. settype ("audio/MP3 ");

Startactivity (it );

Uri uri = URI. withappendedpath (mediastore. Audio. Media. internal_content_uri, "1 ");

Intent it = new intent (intent. action_view, Uri );

Startactivity (it );

Market Problems

1. // search for an application

2. Uri uri = URI. parse ("Market: // search? Q = pname: pkg_name ");

3. Intent it = new intent (intent. action_view, Uri );

4. startactivity (it );

5. // Where pkg_name is the full package path for an application

1. // display information about an application

2. Uri uri = URI. parse ("Market: // details? Id = app_id ");

3. Intent it = new intent (intent. action_view, Uri );

4. startactivity (it );

5. // Where app_id is the Application ID, find the ID

6. // by clicking on your application on market Home

7. // page, and notice the ID from the address bar

Uninstall Application

1. Uri uri = URI. fromparts ("package", strpackagename, null );

2. Intent it = new intent (intent. action_delete, Uri );

3. startactivity (it );

(To) summary of the basic usage of intent

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.