What is Service in android?
Ans: A Service is a android application component which will be used to run long running task.Service will run in back ground. A Service can be created by extending "Service" class.
Unlike thread a Service will run in same process.Service can be started from other android components.
What are the different types of Services?
Ans: Android provide two types of Services:
- Local Services
- Remote Services
- onCreate()
- onBind() -- Required if it is remote service
- onStartCommand()
- onDestroy()
Services are low priority components in android and android system can kill services whenever it requires to allocate resources to higher priority tasks then by depending on Stick Intent value it will decide how to restart service.
Can I make my Service run all the time?
Ans: Theoretically it is supposed to be run all the time but generally Android will kill service whenever it need resources such as memory and processor , by returning START_STICKY intent from onStartCommand() we can ask Android system to restart it whenever resources available , another procedure is use AlarmManager to start service periodically.
What is foreground Service?
Ans:Unless background service it will have more priority , by using setForeGround() method we can make it foreground service.
Can I display or update UI from Service?
Ans: NO. To draw any UI component it should be done from UI thread. We can use Notification Manager to send notifications to the user.
If I start same service multiple times does it create multiple instances of Service?
Ans: NO.
Can I display or update UI from Service?
Ans: NO. To draw any UI component it should be done from UI thread. We can use Notification Manager to send notifications to the user.
If I start same service multiple times does it create multiple instances of Service?
Ans: NO.
nice...
ReplyDeleteThis comment has been removed by the author.
ReplyDeletenice it is very good informative Blog
ReplyDeleteandroid Training in Chandigarh
Android Training in Chandigarh»