Life cycle of Android test service

Source: Internet
Author: User

1  PackageCOM.EXAMPLE.MYAPP4;2 3 Importandroid.support.v7.app.ActionBarActivity;4 Importandroid.content.Intent;5 ImportAndroid.os.Bundle;6 ImportAndroid.view.Menu;7 ImportAndroid.view.MenuItem;8 ImportAndroid.view.View;9 ImportAndroid.widget.Button;Ten /** One * Android Record service life cycle (need to introduce service class name in configuration file) A  * @authorshaobn -  * -  */ the  Public classMainactivityextendsactionbaractivity { -     PrivateButton Startbutton; -     PrivateButton Stopbutton; - @Override +     protected voidonCreate (Bundle savedinstancestate) { -         Super. OnCreate (savedinstancestate); + Setcontentview (r.layout.activity_main); AStartbutton = (Button) This. Findviewbyid (r.id.button1); atStopbutton = (Button) This. Findviewbyid (r.id.button2); -Startbutton.setonclicklistener (NewMyclick ()); -Stopbutton.setonclicklistener (NewMyclick ()); -     } -      Public classMyclickImplementsview.onclicklistener{ - @Override in          Public voidOnClick (View arg0) { -             //TODO auto-generated Method Stub to             Switch(Arg0.getid ()) { +              CaseR.id.button1: -Intent Intent =NewIntent (mainactivity. This, MyService.class); the StartService (intent); *                  Break; $ Panax Notoginseng              CaseR.id.button2: -Intent Intent2 =NewIntent (mainactivity. This, MyService.class); the StopService (intent2); +                  Break; A             } the         } +          -     } $}
1  PackageCOM.EXAMPLE.MYAPP4;2 3 ImportAndroid.app.Service;4 Importandroid.content.Intent;5 ImportAndroid.os.IBinder;6 7  Public classMyServiceextendsService {8 @Override9      Public voidonCreate () {Ten         //TODO auto-generated Method Stub OneSystem.out.println ("--create"); A         Super. OnCreate (); -     } - @Override the      Public intOnstartcommand (Intent Intent,intFlagsintStartid) { -         //TODO auto-generated Method Stub -System.out.println ("--onstartcommand"); -         return Super. Onstartcommand (Intent, flags, startid); +      }  - @Override +      Publicibinder onbind (Intent arg0) { A         //TODO auto-generated Method Stub at         return NULL; -     } - @Override -      Public voidOnDestroy () { -         //TODO auto-generated Method Stub -System.out.println ("--ondestroy"); in         Super. OnDestroy (); -     } to  +}

Life cycle of Android test service

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.