Knowledge points that are encountered during Android learning

Source: Internet
Author: User

The following are some of the records in the study of some of the points of knowledge that need to master, because I learned from scratch, so there are difficult friends can directly ignore this part:

Intent usage:

 1  Uri Myuri = Uri.parse ("http://www.flashwing.net" );  2  Intent openbrowserintent = new  Span style= "color: #000000;"  > Intent (Intent.action_view, Myuri);   3  startactivity (Openbrowserintent);    4  5  6  Intent openwelcomeactivityintent= new    Intent ();  7  openwelcomeactivityintent.setclass (Androidstudy_two.this , Welcome. class   );   8  startactivity (openwelcomeactivityintent); 

To pass data from the source Activity:

1 //Data Write Intent2Intent openwelcomeactivityintent=NewIntent (); 3Bundle mybundelforname=NewBundle (); 4Mybundelforname.putstring ("Key_name", Inname.gettext (). toString ()); 5Mybundelforname.putstring ("Key_age", Inage.gettext (). toString ()); 6 Openwelcomeactivityintent.putextras (mybundelforname); 7Openwelcomeactivityintent.setclass (Androidbundel. This, Welcome.class); 8StartActivity (openwelcomeactivityintent);

Get data from Intent

1  This . Getintent (). Getextras ();   2 String name=mybundelforgetname.getstring ("Key_name");  

Transfer a service request to the target activity through a Intent from the source request activity

1 PrivateIntent tonextintent;//Intent member Declaration2Tonextintent =NewIntent ();//Intent Definition3Tonextintent.setclass (TwoActivityME3. This, SecondActivity3.class); 4 //set the next Activity to open5 Startactivityforresult (Tonextintent,request_ask); 6 //when the Intent is turned on, the request code is delivered simultaneously

Wait for Intent to return the answer result in the source request Activity, by overloading the Onactivityresult () method

1 @Override2 protected voidOnactivityresult (intRequestcode,intResultCode, Intent data)3 {  4   //TODO auto-generated Method Stub5   Super. Onactivityresult (Requestcode, ResultCode, data); 6   if(Requestcode = =request_ask)7   {  8     if(ResultCode = =result_canceled)9     {  TenSettitle ("cancel****" );  One     }   A     Else if(ResultCode = =RESULT_OK) -     {   -Showbundle = Data.getextras ();//get bundles from the returned Intent theName = showbundle.getstring ("MyName");//get the data from the bundle -Text.settext ("The name get from the second layout:\n" +Name);  -     }   -   }   +}

* The first parameter is the corresponding request code when you open the request Intent, you can define it yourself.
* The second parameter is the validation result code returned by the target Activity
* The third parameter is the Intent that the target Activity returns

The target activity sends the request result code, together with the data from the source activity request, bound to the Bundle through the Intent to return the source request activity

1 New Intent ();   2 New Bundle ();   3 stringbundle.putstring ("MyName", Name);   4 Backintent.putextras (stringbundle);   5 // return Activity result code   6 finish ();  

Use the service for music playback
Service definitions in Manifest.xml

1 <ServiceAndroid:name=". Music ">  2 <Intent-filter>  3   <ActionAndroid:name= "Com.test.service.START_AUDIO_SERVICE"/>  4   <categoryAndroid:name= "Android.intent.category.default"/>  5 </Intent-filter>  6 </Service>  

The Player in the Service sub-class

1  Public voidOnStart (Intent Intent,intStartid) {  2   Super. OnStart (Intent, Startid); 3Player = Mediaplayer.create ( This, r.raw.seven_days); 4 Player.start (); 5 }  6  Public voidOnDestroy () {7   Super. OnDestroy (); 8 Player.stop (); 9}

The intent defined in the Activity opens the corresponding

1 startservice (new Intent ("Com.test.service.START_AUDIO_SERVICE"));   2 stopservice (new Intent ("Com.test.service.START_AUDIO_SERVICE"));  
1Displaymetrics displaysmetrics=NewDisplaymetrics (); 2 //Displaymetrics A structure that describes common display information, such as display size, density, font size3 Getwindowmanager (). Getdefaultdisplay (). Getmetrics (Displaysmetrics); 4 //GetManager () Gets the manager that displays the custom window. 5 //get the Display object displayed by default6 //Initializes a Displaymetrics object with data from the Display object7   8   9Title bar/status bar hidden (full screen)Ten //Hide Title One requestwindowfeature (Window.feature_no_title);  A //defining full-screen parameters - intFlag =WindowManager.LayoutParams.FLAG_FULLSCREEN;  - //Get Window Object theWindow Mywindow = This. GetWindow ();  - //set the Flag ID -Mywindow.setflags (Flag,flag);

button-Pressed processing:

(1)

1 Press = (Button) Findviewbyid (R.id.click_button);  
1 press.setonclicklistener (new  button.onclicklistener ()  2{   3   @Override  4public   void  OnClick (View v)   5   {  6     //  TODO auto-generated method stub  7    }  8 });  

(2)

1Press.setonclicklistener ( This); 2 @Override3  Public voidOnClick (View v)4 {  5   Switch(V.getid ())/*Judging button events by ID*/  6   {  7      CaseR.id.click_button:8     {  9     }  Ten      Break;  One     default:   A      Break;  -   }   -}

Toast--android Exclusive Floating Tips
(1) display text: Toast.maketext
(2) Display Image:

1 /*Create a new Toast object*/  2Toast showimagetoast=NewToast ( This); 3 /*Create a new ImageView object*/  4ImageView imageview=NewImageView ( This); 5 /*get a picture from a resource*/  6 Imageview.setimageresource (r.drawable. Argon); 7 /*set view--on Toast (ImageView)*/  8 Showimagetoast.setview (ImageView); 9 /*Set Toast display time*/  Ten showimagetoast.setduration (Toast.  Length_long);  One /*Show Toast*/   AShowimagetoast.show ();

Simulator Debug:

1 New // If you cannot connect  successfully with localhost

Points of knowledge encountered during Android learning

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.