interview in android , Android InterView Question And Answer
An interview in android , best Answered .
Raj is having , 0 - 2 years , experience as a programmer , in android
He is having a technical round , lets see how clearly he replies to questions.
Interviewer Started by asking : " Explain the Aplatform architecture of android. "
Raj replied "
Android is an open source, Linux-based ,software stack . Android is an open source, Linux-based software stack. It comprises of Linux Kernal , Hardware Abstraction Layer. Native Libraries, Android RunTime, Java APIs , System Apps. Below Of Stack is : The Linux Kernel : , Linux kernel provides drivers for connecting to hardware. The hardware abstraction layer (HAL) , provides a standard interfaces , that interact with Kernal drivers , to access hardware features. Android Run Time , is written , to run multiple virtual machines , on low-memory devices , by executing DEX files . For devices running Android version 5.0 (API level 21) or higher, each app runs in its own process and with its own instance of the Android Runtime (ART). Prior to Android version 5.0 (API level 21), Dalvik was the Android runtime Native C/C++ Libraries Android components such as ART and HAL, are built from native code that require native libraries written in C and C++. Android provides Java APIs to use functionality of native libraries to apps ..Java API Framework Java APIs form the building blocks you need to create Android apps by providing components and services.System Apps Android comes with , a set of core apps , for email , SMS messaging , calendars, internet browsing , contacts , and more. "
InterViewer : "good! very well explained. Can u explain activity lifecycle ? "
Raj Replied "
Yes Sure.. An activity has essentially four states: If an activity is in the foreground of the screen , it is active or running. If an activity , has lost focus , but is still visible , (like in case of dialog comes top), then it is paused. If an activity is completely obscured by another activity, it is stopped. It still retains all state and member information. If an activity is paused or stopped, the system can drop the activity from memory by either asking it to finish, or simply killing its process.
So , when the activity is first created its onCreate() method gets called .
onStart() get called after onCreate() when the activity is becoming visible to the user.
After it onResume() is being called when the activity will start interacting with the user.
onPause() is called when the system is about to start resuming another activity or when its looses focus like when some dialog comes top of it.
onStop() called when the activity is no longer visible to the user, because another activity has been resumed and is covering this one.
onRestart() is called if this activity is coming back to interact .
If the activity is finished , the final call activity will recieve is onDestroy(). That completes whole activity cycle."
Interview : "Thats excellent !"
Interview : "
Lets say ,there are three activities A , B , C each having button to start activity without finishing in order A start’s B, B start’s C, C start’s A. Can you show me what all set of lyfecycle method gets called while navigation from A to B,
B to C,
C to A "
Raj Replied :
" Ok. When Activity A started , its onCreate() , onStart(), onResume() , gets called in order When Activity B started , A : onPause() gets called , then B: onCreate() , onStart(), onResume() gets called in order When Activity C started , B : onPause() gets called then C: onCreate() , onStart(), onResume() gets called in order , then B: onStop() When again Activity A started from C , As A was not destroyed So first C: onPause() gets called then A: onRestart() , onStart(), onResume() , gets called in order then C: onStop() . "
InterViewer : " Thats excellent ! "
InterViewer : " What is Service in android and what are their types? "
Raj Replied :
"A Service is an application component that can perform long-running operations in the background, and it does not provide a user interface. These are the three different types of services: Scheduled , Started , Bound
A service is scheduled when an API such as the JobScheduler , launches the service.
A service is started when an application component (such as an activity) calls startService().
After service started, it can run in the background indefinitely, even if the component that started it is destroyed. It is stopped by stopService() method. The service can stop itself by calling the stopSelf() method.
A service is bound when an application component binds to it by calling bindService(). A bound service offers a client-server interface that allows components to interact with the service, send requests, receive result. The client can unbind the service by calling the unbindService() method. The service cannot be stopped until all clients unbind the service. "
Inteviewer : " Good Nicely explained. "
Inteviewer : " Can you explain by any real time example when to use bindservice or start service . "
Raj Replied :
" Yes Sure ! , Suppose, I want to play music in the background , so call startService() method. But I want to get information of the current song being played, I will bind the service that provides information about the current song. "
InterViewer : " Ohh! Very , Good Example "
InterViewer : "Ok Tell Me , What is the difference between , Service and Intent Service. "
Raj Replied :
" Service is the base class for all services. Once the service is started, the onStartCommand , method in the service is called. It passes in the Intent object from the startService(intent) call. If startService(intent) is called while the service is running, each time its onStartCommand() is also called. Therefore it's important to create a new thread each time in onStartCommand in which the service can complete all of its work for that particular intent recieved.
While IntentService is a subclass of Service , Creates a work queue , that passes , one intent at a time , to your onHandleIntent() implementation, so you never have to worry , about multi-threading. "
InterViewer : " Very Nice. Now tell me , What is an Intent in android ? "
Raj Replied
:" An Intent is a messaging object ,used to request an ACTION to performed by application component such as Activy , Service , Broadcast Reciever etc. "
InterViewer : " Very Nice. And whats the difference between Implicit Intent and Explicit Intent ? "
Raj Replied :
" Explicit intents specify the component to start by its name (that is , fully-qualified class name) for example : you can start a any new activity by its name or start a service by its name to download a file in the background.
Implicit Intents do not directly specify the Android components which should be called , it only specifies action to be performed , which also allows a component from another app to handle it . "
InterViewer : " Very Nice. what is Broadcast Reciever in Android ? "
Raj Replied :
" Broadcast receivers are components in the application that listen for broadcasts and take some action. for example, building a broadcast receiver to listen for the battery getting low broadcast event in order to inform the user that unsaved data should be saved quickly . "
InterViewer : " Good! , and how many ways app can send Broadcast ? "
Raj Replied :
" Android provides three ways , for apps to send broadcast: first is sendOrderedBroadcast ,
second is thorugh sendBroadcast method ,
third is through LocalBroadcastManager method sendBroadcast . The sendOrderedBroadcast method sends broadcasts to one receiver at a time. As each receiver executes in turn, it can propagate a result to the next receiver, or it can completely abort the broadcast so that it won't be passed to other receivers.
The sendBroadcast method sends broadcasts to all receivers in an undefined order.
The LocalBroadcastManager method sendBroadcast , sends broadcasts to receivers that are in the same app as the sender. If you don't need to send broadcasts across apps, use local broadcasts. "
InterViewer : " Good! , You Have Very Well Answerd to All Your Question. "
That is really helpful
ReplyDeleteNice Session
ReplyDelete