Focus on technology, enjoy life! --Yang Zhou qq:804212028
Original link: http://blog.csdn.net/y18334702058/article/details/44624305
- Topic: Intent Learning
-intent (Intent) is primarily to address communication issues between the various components of an Android application. Intent messaging is a mechanism for running-time binding between components.
Intent and bundle mechanisms
Intent and bundles implement code examples that convert from one activity band parameter to another activity
Bind information in Activity1 's intent.
Intent intent = new Intent(); Bundle bundle = new Bundle(); bundle.putString("NAME""蛋蛋"); intent.putExtras(bundle); intent.setClass(active1.this, active2.class); startActivity(intent);
And get the information out of the activity2.
Bundle bundle = this.getIntent().getExtras(); String str = bundle.getString("NAME"); System.out.println(str);
Intent and Intent filter differences:
-intent is translated as "intent" in Android, and it is the "messenger" that transmits information when Activity,service and broadcast receiver are activated to each other. It is similar to the httpservletrequest in our web.
-While the intent filter is equivalent to the Url-patten we have configured for the servlet, it is used to match a specific intent object.
Intent usage Examples:
Show Web page:
Uri uri = Uri.parse("http://www.google.com");Intent it = new Intent(Intent.ACTION_VIEW,uri);startActivity(it);
Show Map:
Uri uri = Uri.parse("geo:38.899533,-77.036476");Intent it = new Intent(Intent.Action_VIEW,uri);startActivity(it);
Path planning:
Uri uri = Uri.parse("http://maps.google.com");Intent it = new Intent(Intent.ACTION_VIEW,URI);startActivity(it);
Dial number:
Uri uri = Uri.parse("tel:xxxxxx");Intent it = new Intent(Intent.ACTION_DIAL, uri); startActivity(it); Uri uri = Uri.parse("tel.xxxxxx");Intent it =new Intent(Intent.ACTION_CALL,uri);
To use this, you must include it in the configuration file
<uses-permission id="android.permission.CALL_PHONE" />
Send SMS
Uri uri = Uri.parse("smsto:0800000123"); itnew Intent(Intent.ACTION_SENDTO, uri); it.putExtra("sms_body""The SMS text"); startActivity(it
Send MMS
Uri uri = Uri.parse("content://media/external/images/media/23"); Intent it = new Intent(Intent.ACTION_SEND); it.putExtra("sms_body""some text"); it.putExtra(Intent.EXTRA_STREAM, uri); it.setType("image/png"); startActivity(it);
Send email
Uri uri = Uri. Parse("Mailto:[email protected]");Intent it = new Intent (Intent. ACTION_sendto, URI);StartActivity (IT);Intent it = new Intent (Intent. ACTION_send); It. PutExtra(Intent. EXTRA_email,"[email protected]"); It. PutExtra(Intent. EXTRA_text,"The email body text"); It. SetType("Text/plain"); StartActivity (Intent. Createchooser(IT,"Choose Email Client")); Intent it=new Intent (Intent. ACTION_send); String[] tos={"[email protected]"}; String[] ccs={"[email protected]"}; It. PutExtra(Intent. EXTRA_email, TOS); It. PutExtra(Intent. EXTRA_CC, CCS); It. PutExtra(Intent. EXTRA_text,"The email body text"); It. PutExtra(Intent. EXTRA_subject,"The email subject text"); It. SetType("message/rfc822"); StartActivity (Intent. Createchooser(IT,"Choose Email Client"));
Add an attachment
Intent it = new Intent(Intent.ACTION_SEND); it.putExtra(Intent.EXTRA"The email subject text"); it.putExtra(Intent.EXTRA"file:///sdcard/mysong.mp3"); sendIntent.setType("audio/mp3"); startActivity(Intent.createChooser"Choose Email Client"));
Play Multimedia
intent it = new Intent (intent _view) ; Uri uri = Uri.parse ( "File:///sdcard/song.mp3" ) It.setdataandtype (URI, "Audio/mp3" ) Span class= "hljs-comment"; StartActivity (IT) Uri uri = Uri.withappendedpath (Mediastore _content_uri, "1" ) ; Intent it = new Intent (intent _view, URI) ; startactivity (IT) ;
Uninstall Program
Uri uri = Uri.fromParts("package"null); new Intent(Intent.ACTION_DELETE, uri); startActivity(it);
Two methods of passing objects in intent
- One is bundle.putserializable (key,object); The other is bundle.putparcelable (Key,
Object); Of course, these objects have certain conditions, the former is the implementation of the serializable interface, and the latter is the implementation of the Parcelable interface.
Many people know that there are two choices when passing objects between activity, one is parcelable and the other is serializable. But when should we use one of them?
1. When using memory, parcelable analogy serializable high performance, so we recommend the use of Parcelable class.
2.Serializable generates a large number of temporary variables when serializing, causing frequent GC.
3.Parcelable cannot be used to store data on disk, because Parcelable does not guarantee the continuity of the data in the event of a change in the outside world. Although serializable efficiency is low, it is not advocated, but in this case, it is recommended that you use serializable.
Focus on technology, enjoy life! --Yang Zhou qq:804212028
Original link: http://blog.csdn.net/y18334702058/article/details/44624305
Step by Step _android Development Course [4]_intent Study