Answer: D either b or c
Description: Binder is used if both client and server are in same application.
If client and service (server) are in different applications, then this can be implemented in two ways:
1. Messenger - is a simple way to implement binder service, which is single threaded mode.
With this, your service can handle only one client request at a time.
2. aidl (Android interface definition language) - use it if you want multi threaded capability for your server/service
With this, your service can handle multiple requests at a time. But little complicated.
Make sure that you are writing always thread safe program in your service when using with aidls.
This is not recommended for most of the implementations.
Answer: D all are true
Description:
Answer: C onBind() function will be called every time a client binds to the binder service.
Description: Binder Service's onBind() function will be called only once for the first client. From there on wards for every client call to bind this service, android will cache that binder object and return it with out calling onBind() function.
Answer: B bindedservice
Description: it is not a good practice to use started service if service wants to share some functionality with other components. binded services are far more faster and efficient than started service to share functionality with other components. it uses binders concept internally.
Note: Content providers are used to share data between 2 applications, not for sharing functionality.
Answer: C oncreate -> onstartCommand() -> onDestroy()
Description: onCreate() -> onStartCommand() -> onDestroy(). This is the life cycle of a started service. onBind() and onUnbind() will come into picture for only binded services. previously in old versions onStart() was there in place of onStartCommand().
Answer: A Don't give any intent-filters for your service tag [or] put exported="false" in service tag [or] LocalServiceManager
Description: If you don't want to expose your service to outside apps, 3 ways are there. 1. Don't give intent-fiiter tag, so that outsiders can't specify intent action to trigger your service. or 2. User exported="false" in service tag, so that outside world cant trigger it. or 3. User local service manager.
Answer: C you can either use option 1 or option 2, based on your requirement. But most of the times it is better to use option 2.
Description: it is better to use services with thread, because threads in activity will have less priority compared to thread in a service in case if that activity is in background or stopped state. more over in case of low memory if it kills thread in activity, there is no way that android will recreate it. all these disadvantages are overcome in services with android. But still if you want to use a thread with activity then as long as programmer make sure that cleaning and creation of thread is done properly, then there won't be any problem.
Answer: A You can start service from any where, but still oncreate, onstartcommand runs in main thread only.
Description: You can start service from any where, but still oncreate, onstartcommand runs in main thread only.
Answer: C it behaves weirdly, either toast message may not appear or it appears and will be never removed. this happens because other thread is touch ui with out informing to main thread.If you try to touch other UI components, it will crash.
Description: it behaves weirdly, either toast message may not appear or it appears and will be never removed. this happens because other threads can't touch UI with out informing to main thread.If you try to touch other UI components, it will crash.
IntentService onHandleIntent() functions runs in worker thread (not main thread). So don't try to touch UI elements from that function directly.
Answer: B call startForeground(int id, Notification notification);
Description:
Answer: B In case if client is in different process and service(Server) is in different process, then we should always use aidl to implement it.
Description: If client and server are in different processes, then there are two ways to implement service. 1.creating a singled threaded server using Binder and Messenger or 2. Creating multi threaded server using aidls.
Answer: D iv
Description: Binders won't use serialization concept for marshaling or converting data into byte streams. it uses Parcels instead.
Answer: C Use .aidls and implement the stub.
Description: If we want to create a service with multi threads and supports binders then we have to use .aidls and implement the stub.
Answer: D bindService() function is an asynchronous call which returns immediately. after returning, connection will be established after some time.
Description: bindService() function is an asynchronous call which returns immediately. after returning, connection will be established after some time.
Answer: C Binder extended class can return any other class's object of Service, whose public functionalities can be accessed by client.
Description: Using binder services we can share below functionalities from binder service 1. Public methods of Binder extended class 2. Public methods of Service class, by returning this pointer of the Service class 3. Any other Service inner class's public functionalities by returning object to that class.
Answer: C i, ii & iii
Description: Below are the functionalities of Binder class.
1.Marshaling & Un-marshaling of out gong and incoming data across the processes
2. thread management for service class as incoming call from multiple clients may come from different threads.
3. Binder's stub functionality has to be implemented by the programmer.