Triển khai services trên android
Dự án retailsmarter sau này sẽ cần dùng đến để chạy ngầm và nạp dữ liệu cho widget sản phẩm hoặc top sản phẩm
To create a application to run in the background of other current activities, one needs to create a Service. The Service can run indefinitely (unbounded) or can run at the lifespan of the calling activity(bounded).
Please note that a Service has a different lifecycle than activities therefore have different methods. But to begin a service in the application a call to
startService() which envokes the service
onCreate() method and
onStart() beginning running the service.
context.startService() | ->onCreate() – >onStartCommand() [service running]
Calling the applications
stopService() method to stop the service.
context.stopService() | ->onDestroy() [service stops]
Something that we didn’t use in this example is bindService() which just calls the services onCreate() method but does not call the onStartCommand(). onBindService() is used to create persistance connection to the service.
context.onBindService() | ->onCreate() [service created]
This Services Demo is simple as it plays a audio file and by listening to click events…
View original post 362 more words