Select chapter



basics (6.papers)
activities (5.papers)
services (2.papers)
threads (2.papers)
receivers (1.papers)
advanced android (2.papers)
SQLite database (1.papers)
adapters (1.papers)
adb and ddms (1.papers)
widgets (1.papers)
fragments (1.papers)
UI (1.papers)
Hide

Sponsored Links


  

android interview questions and answers

1
What is the difference between service and a thread?
  1. Service - is a component of android, which runs in the background with out any UI. Service will have default one thread to run in the back ground. Thread - is similar to service, it also runs in the background
  2. Service - is a component of android, which runs in the background with out any UI. By default service will run in Main thread only. Thread - is not android component, but still one can use thread to do some background task. Using thread in place of service is discouraged.
  3. Option 2 is right, but one can use Thread in place of Service, no problem will come.
  4. Option 1 is right, but it may have UI also some times.
Show Answer
Share Facebook gmail Twitter
2
start a service from activity and close activity, what will happen to that service, will it be alive or dead?
  1. service will also be killed
  2. service will be alive for some time, and will be killed by android garbage collector.
  3. service will run for ever, no body can stop it now, and it leaks memory.
  4. service will be keep running in the background, but it can stop itself when the work given to it is done. Or others also can kill that service using stopService(), or android also can kill the service forcefully in case of low memory scenarios.
Show Answer
Share Facebook gmail Twitter
3
How to stop a service in android?
  1. stofSelf()
  2. stopService()
  3. android may also kill service forcefully in cases of low memory
  4. all above options are rite
Show Answer
Share Facebook gmail Twitter
4
Bound service : binding to a service, what is the function that needs to be implemented in service class?
  1. onCreate()
  2. onBind() & onUnbind()
  3. ServiceConnectionListener in client side.
  4. all above 3 are required.
Show Answer
Share Facebook gmail Twitter
5
How to create a service with multiple threads in it?
  1. Create a service with creating thread in onStartCommand
  2. Use Intent Service
  3. Create a service with one thread in OnCreate().
  4. Either use option1 or use Async task with service
Show Answer
Share Facebook gmail Twitter
6
How to update UI from a service that has threads?
  1. Create a thread in the Service class and directly access UI components of your activity
  2. Since updating UI from other thread directly is not possible, communicate with Main UI thread for the UI updates
  3. Use Intent Service
  4. Either use option1 or option 2
Show Answer
Share Facebook gmail Twitter
7
How to start a service with foreground priority?
  1. Service always runs in background since it doesn't have UI, so its not possible.
  2. startService(intent, boolean foreground); pass second parameter true, to make this service as foreground.
  3. Set priority to service in <service> tag in the manifest file. if priority is any thing other than 0, then it will be treated as foreground service.
  4. startForeground (int id, Notification notification), use this function in onCreate() of your service.
Show Answer
Share Facebook gmail Twitter
8
Service with threads: My application has only a service, and my service performs heavy lift functionality to connect to internet and fetch data, now should I create a thread or not? If so why?
  1. Yes, because by default services with out any thread uses Main thread.
  2. Option 1 is right, because if services and activities runs in only one thread, it may lead to ANR error.
  3. No, you don't need to create a thread because a service will create a thread in the back ground when ever some one starts your service.
  4. No need to create a new thread in Service as it is not required in this scenario. Because service runs in the main thread. Since our app doesn't have any activities, so its OK to run service in main thread.
Show Answer
Share Facebook gmail Twitter
9
Is it possible to have a service with multiple threads in it? How to achieve this?
  1. you can't have more than one thread in a service.
  2. you can create multiple threads in a service.
  3. option 2 is possible by creating thread in onCreate().
  4. option 2 is possible by creating thread in onStartCommand() of your service class.
Show Answer
Share Facebook gmail Twitter
10
How to pass data from activity to service?
  1. pass data in intent-putextras, and using setResult()
  2. pass data in intent-putextras, and say startService() with that intent
  3. store it in common database and access it through both activity and service.
  4. can be done using both the ways 2 and 3 options.
Show Answer
Share Facebook gmail Twitter
11
Updating UI from service: How to access progress bar from a service?
  1. Send progressbar id through intent extras & access it in service
  2. Make progress bar as static variable in activity, and access that variable from service.
  3. If you want to touch UI from service, trigger a dynamically registered receiver in activity from service. And update UI from that dynamic receiver with in that activity.
  4. put all UI controls in a common class and access it from all components.
Show Answer
Share Facebook gmail Twitter
12
What is the difference between startservice and bindservice?
  1. started service - runs in background for ever unless some one or itself stops. it is used to perform long running operation. Binded service -  is alive as long as some one binds to it and interacts with it. binded services can return value to the person who bound to it.
  2. started service - runs in background for ever unless some one stops. started services can return values to person who started it. Binded service -  is alive as long as some one binds to it and interacts with it, and after work is done, the person who has bind to it has to unbind it.
  3. started service - runs in background for ever in different thread. Binded service -  is alive in separate thread as long as some one binds to it and interacts with it
  4. started service - run sin background and is alive as long as the component who started is also alive. Binded service - is alive in background as long as component who connected to it is also alive.
Show Answer
Share Facebook gmail Twitter
13
What are the various return values of onStartCommand() , and when to use what?
  1. START_STICKY - in case if android stops our service forcefully, then restart service by sending intent null
  2. START_NOT_STICKY - in case if android stops our service forcefully, then don't restart service, until user restarts it.
  3. START_REDELIVER_INTENT - in case if android stops our service forcefully, then restart service by sending re-sending the intent.
  4. all options are true
Show Answer
Share Facebook gmail Twitter
14
How to monitor service connection status in bound services?
  1. using isServiceConnected(), it returns true if service is connected
  2. using onServiceDisConnected(),  this function will be called if connection is broken
  3. client can keep polling to service if it is available or not.
  4. using ServiceConnection class.
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
16
How to implement IPC (Inter process communication) using binders?
  1. 1. create a service & implement onCreate(), onBind(), onUnbind(), onDestroy()
    2. create .aidl file with interface functions.
    3. implement auto generated Binder stub class in service.
    4. return object to this stub class from onBind()
  2. 1. create a service & implement onCreate(), onBind(), onStartCommand() ,
       onUnbind(), onDestroy()
    2. create .aidl file with interface functions.
    3. implement auto generated Binder stub class in service.
    4. return object to this stub class from onStartCommand()
  3. 1. create a service & implement onCreate(), onBind(), onStartCommand() ,
       onUnbind(), onDestroy()
    2. create a inner class in Service class that extends Binder class
    3. Implement functions to be exposed in this inner class
    4. return object to this inner class from onStartCommand()
  4. 1. create a service & implement onCreate(), onBind(), onUnbind(), onDestroy()
    2. create a inner class in Service class that extends Binder class
    3. Implement functions to be exposed in this inner class
    4. return object to this inner class from onBind()
Show Answer
Share Facebook gmail Twitter
17
Service or thread: To do background functionality in activity, is it better to start service or thread? why?
  1. you can use both, because both will do same thing.
  2. If that background functionality is co-related with activity, then use thread. else launch it in a new service with thread in the service.
  3. whether that background functionality has any thing to do with activity or not, it is always better to use service with a thread, rather than using thread with activity.
  4. if you want  some background functionality in activity, directly for only thread. no need of service there.
Show Answer
Share Facebook gmail Twitter
18
Is it possible to have a service without any thread?
  1. yes, you can have service running in main thread
  2. No, service should have a thread, it can't run in main thread
  3. option 1 is O.K only if you are not running any activity in Main thread.
  4. Thread and service is no way related
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
20
In case of low memory if android closes a service forcefully, then will it restart automatically or user has to start that service?
  1. It will never be restarted again by Android.
  2. User has to restart it again.
  3. Option 1 is true only if programmer has not returned START_NOT_STICKY from onStartCommand()
  4. Option 1 is true if programmer has returned START_STICKY or START_NOT_STICKY
Show Answer
Share Facebook gmail Twitter
Read more papers :