1. Practice service Start () method to open a service, no matter how to open the button, is not open the service services, the console also does not have error messages,
The app does not flash, and the code is just a few lines away. I couldn't find it for a long time. At last, I looked at the video again, and the service was not registered in the manifest file. Whether it's activity or service,
Must be registered in the manifest file. The best way to do this is to write an activity or service and register it in the manifest file immediately.
Knowledge Points:
1 by
StartService (New Intent (Mainactivity.this,mystartservice.class));
When a service is opened in this way, the mystartservice automatically calls the OnCreate () method, and then calls the
Onstartcommand (Intent Intent, int flags, int startid)
This method, if you click on the button StartService (intent), then Mystartservice will not call the OnCreate () method, but the direct Onstartcommand () method.
StopService (Intent Intent); OnDestroy () method is called later.
An official life cycle chart is as follows:
Local address: E:\docs-14_r01\docs\guide\topics\fundamentals\services.html,
Android:service points of attention and some knowledge points