Android Interview Questions for 1 – 2 year of Experience Developer – Including Answers
We have put together some interview questions which are going to improve your android skills. If you are an experienced android developer who is preparing for an interview exam, then these questions are going to help you clearing the technical interview round. You can study these questions in any order. All in all these questions are going to improve your existing knowledge about android framework. Good luck.
Note: This post is getting updated regularly. We are adding 2 to 3 questions on daily basis. Keep reading everyday to see the new questions.
Question #1: Explain the use of onCreate() method by looking at following code snippet of it.
public void onCreate(Bundle savedInstanceState)
If you are an experienced android developer then interviewer expects you to answer this question in detail. You can explain onCreate() method in following way.
onCreate() is the very first method which gets called whenever an activity is created. In this method you should initialize the essential components used by your activity, create views, bind data to lists, etc.
Bundle object is passed into onCreate()
A Bundle object is passed whenever android system calls the onCreate() method. Bundle contains information regarding the previous state of your activity. By using it you can restore the state in any scenario (such as change in screen orientation) in which onCreate() method is called again. It helps to retrieve all resources, including layouts, drawables, and strings.
Whenever you override any activity life cycle method you should call its super method (which is present in parent class).
Your activity inherit the Activity class and onCreate method of parent class (Activity) should be called in order to perform the necessary initial set up for your activity (such as assigning context to an activity).
In this way both onCreate (subclass and superclass) methods gets called by the android framework.
setContentView() method helps to define the layout for an activity. This method takes resource id of the layout as a parameter.
Question #2: What happens when you don’t call super.onCreate() method in onCreate()?
Answer: Android framework will throw an exception by the name of SuperNotCalledException. Your implemented activity will not work without calling this method. super.onCreate() is required to perform the necessary initial set up, assignment of context to an activity, etc.
Question #3: We are writing an android app which loads some data from remote database using a URL. While doing so we encountered network on main thread exception. What did we do wrong and how can we handle it?
You should be easily able to answer this question if you have 1 or more year of experience in android development.
Answer: Receiving data from URL is a time taking operation. If we fetch data from URL on main thread then we get network on main thread exception.
Main thread is also know as User Interface (UI) thread and it gets blocked when we do any blocking operation. We can use background thread to properly load data from URL.
Question #4: What happens to the activity life cycle whenever a user is browsing your application and suddenly a call comes?
Answer: Your activity goes to the background state and another activity corresponding to the phone call comes in the foreground. onPause() method followed by onStop() method gets called whenever a call arrives on the device.
Note: If you have some experience in android app development then you should know the activity life cycle in detail. That’s why we are going to list a few questions which are going to help you. These questions have chances of being asked in an android interview/test.
Question number 5 to 8 are going to improve your knowledge about callback of android life cycle methods.
Question 5: Which activity life cycle methods are called whenever a call ends?
Answer: Below methods are called in an order in which they are written.
Question 6: Which activity life cycle method gets called whenever you open an app for the first time?
Answer: See methods listed below in given order.
Question 7: Which activity life cycle method gets called whenever the screen of the device turns off an then turns on?
When screen Turns off:
When screen Turns on:
Question 8: Which activity life cycle method gets called whenever a dialog opens on screen?
Answer: onPause() gets called whenever a dialog appears on screen. Also onResume() gets called when you dismiss the dialog or press back button while dialog is on the foreground.
Question 9: When is it ideal to use AsyncTask?
Answer: You can use AsyncTask when you require to perform a long running running operation followed by UI changes. For example, loading of an image from URL.
With AsyncTask you can even perform multiple UI updates during background operation. You can use onProgressUpdate() method to perform multiple UI updates (like showing percentage of work done) during the background execution.
Note: We are adding new android interview questions for experienced developers on regular basis. So bookmark this page for your reference and keep reading. Thank you.