MVVM common interview questions and answers

Here is the next best thing for Android developers: a list of commonly asked Android interview questions. Here are the top Android interview questions and their answers prepared by Android experts. These Android developer interview questions cover various topics like MVVM, ART, ConstraintLayout, fragment, activity and help you understand the different purpose of AndroidManifest.xml file.

There is no direct way to terminate a thread but using the two following ways it can be done.

MVVM stands for Model-View-ViewModel. Android applications built using MVVM are more robust, fast, scalable and very less prone to memory leaks. In MVVM ViewModel is the key between View and Model.

The important key point about MVVM is that View has reference to the ViewModel but not in reverse and that makes the application’s UI-Components related memory leak-proof. Each View may have a dedicated ViewModel or may be shared by multiple in case of fragments to enable sharing data cross fragments of an activity. MVVM is a more suitable candidate for automated testing.

It stands for Android Run Time. ART is used for running Android applications. It uses AOT (Ahead Of Time) compilation on the device. When an APK is getting installed on the Android device, the .dex files from the APK file will be converted to processor’s native instructions set/machine code (.art extension) and that will be stored in the app’s runtime cache directory on the device’s internal storage. This will make installation little bit longer and take more space on the device storage but it makes apps run much faster, less battery consumption, robots application debugging support and better user experience.

The recommended way going forward is using WorkManager APIs, that makes it easy to specify deferrable, asynchronous tasks and when they should run under the circumstances you choose, or recurring tasks that run at a specified interval. Internally WorkManager might use JobScheduler, Firebase-JobDispatcher, Executor, and AlarmManager for running the task.

Android is a ‘Linux based software stack’ created for a wide array of devices and form factors. It is open source. It has layers of major components from bottom to top as follows…

It is the foundation for any Android application. It will be in app module’s src/main/ directory for Android Studio projects. This file contains information of application package, including components of the application such as activities, services, broadcast receivers, content providers etc. It performs some other tasks also: It is responsible to protect the application to access any protected parts by provision of permissions.

In Android, UI is representing as an Activity. Single Screen in an application represents as Activity while Fragments are reusable UI with business logic. Activity is a collection of Screen. In android application, Fragments are using in Navigation Drawer in our entire screen. You can also use fragment to display Google Map on screen.

Android OS provides back stack function for Activity, it also provides back stack function for Fragment. If you add one Fragment into the back stack, when you press the android device back menu, you can find the Fragment that is saved in back stack popup. Until all saved Fragments in back stack popup, then the activity will exit.

We have to create “FragmentTransaction objects on the back stack and when the user presses the Back button, the “FragmentManager pops the most recent transaction off the back stack and performs the reverse action.

In Android when we want to share data between two applications we are using Content Provider. It has a complete mechanism to share data between applications. It will also provide security while sharing data from one application to another application. For getting data from any Content Provider you need to create Content Resolver. For Creating Content Resolver, you need to call Activity’s getContentResolver method.

For Modifying data from Content Provider, you can invoke the basic method of Content Resolver like insert, delete, update and query. These operations are the same as the SQLite DB Operation.

For this, we can modify our build Gradle file of the application. In Gradle file we will add code for adding build type and build flavour like below:

When you need to send Object from one activity to another activity, we are using two techniques: 1. Serialization and 2. Parcelable. In other case passing data from one activity to another activity, we are using Intent. Parcelable is a faster approach compared to Serialization because it is using Android SDK.

Launch mode is an instruction for Android OS which specifies how the activity should be launched. It instructs how any new activity should be associated with the current task.

So in your scenario When using launchMode=”singleInstance”, there are two things that we need to remember:

As such, an Activity with launchMode of singleInstance will always be isolated in its own task. There wont be another Activity inside of that task.

From what happened here, you have one a task that stores the launchMode=”standard” Activity A and Activity C. Activity B is in its own task. Activity D is in its own task.

Also, Activity D definitely wont be in the same task as Activity B because Activity Bs task is meant only for Activity B due to launchMode=”singleInstance”.

In Android Service is something that is running in the background. In a simple way, we can say that a background service is same as an Activity. The only difference is it doesn’t have UI. A background Service can be started by calling the startService method in your Activity. we need to create an explicit Intent, which means that you either make a reference to the Service’s class, or you include the package name of your app in the Intent. For example:

There is one drawback with Service is that it is running on Main Thread so you can not assign any long running operation to service. But if you want to run some long running operation in the background, you should use IntentService.

IntentService is creating its own Worker Thread which is running separately from the Main Thread. Examples for its usage would be to download certain resources from the Internet. For creating Intent Service you need to create a service class by extending IntentService and implementing onHandleIntent() method.

In Intent Service we can start service by calling startService method passing intent which identifies the service. We can call startService any number of times, but in the background it will create only one instance of intent service and all requests are queued and processed in separate work thread. We don’t need to worry about calling stopService, as IntentService stops itself when there are no requests to serve.

In Android Sticky Intent is a type of Intent who will communicate between Service and Function. Sticky Intent is using with Sticky Broadcast that’s why they are calling as StickyIntent. In simple language, we can say that StickyIntent is stick with till Broadcast is not completed its job this intent will be present and return data of registerReceiver() method and will be re-delivered or re-broadcasted to the future requests from any broadcast receivers. We have one more advantage of Sticky Intent that Sticky Broadcast will replace the previous instance of the sticky broadcast and save your application from memory leak.

For example, if we need to send a notification for Low status of Battery, we will create a sticky broadcast sent via the operating system is ACTION_BATTERY_CHANGED. As soon broadcast that action we will get the Intent with data. For this first, we need to add special permission in the manifest file that allows an application to broadcast sticky intents.

View is a basic building block of UI (User Interface) in android. A view is a small rectangular box which responds to user inputs. For example, a Text View is used to display some text to the user that is a subclass of View. In Android, we are using many View subclass like EditText, Button, CheckBox, Radio Button, View, DatePicker etc.

ViewGroup is an invisible container of other child view. ViewGroup is a special kind of view which is extended from View as its base class. ViewGroup is the base class for layouts. Viewgroups can contain other views in it. For example LinearLayout, it is a group of many views those are arranging in Linear or Veridical way. In Android, we have other layouts as well like Relative Layout, Table Layout, Frame Layout etc.

The Recycler view is the most advanced component of Android. We can also say that RecyclerView is the most advanced form of ListView. Recycler view is containing new feature like ViewModel, Adapter, LayoutManager, SoothScroller. There are many differences many difference between listview and RecyclerView.

In ListView we cannot do horizontal scrolling while in RecyclerView we have both option Horizontal and Vertical Scrolling.

In RecyclerView class, it is using a ViewHolder object which is used by the adapter to bind ViewHolder with a position while in ListView we are not using ViewHolder.

In ListView, if the data set is changed you have to call the notifyDataSetChanged method of the underlying adapter to refresh data. While in a RecyclerView adapter, if a single item or a range of items have changed, there are methods to notify the change accordingly like notifyItemChanged and notifyItemRangeChanged.

Having rotated the device, the following state change sequence should appear Clearly this has resulted in the activity being destroyed and re-created. To save the state information override onSaveInstanceState() method and add key-value pairs to the Bundle object. It will save data in the event that your activity is destroyed unexpectedly. This method gets called before onStop(). To get saved from an activity state, we are using method onRestoreInstanceState.

The first step in extending the StateChange application is to make sure that the text entered by the user is extracted from the EditText component within the onSaveInstanceState() method of the StateChangeActivity activity and then saved as a key-value pair into the Bundle object.

Alternately, use the onRestoreInstanceState( ) method to extract saved state from the Bundle and restore it into new instances of the activity. The onRestoreInstanceState( ) method is another callback lifecycle method that is also rarely seen in the activity lifecycle diagrams. The onRestoreInstanceState( ) method is automatically invoked by Android between the onStart( ) and the onResume( ) lifecycle methods.

You can do it by setting an OnKeyListener on your EditText. This is only useful for hardware keyboards. A software input method has no obligation to trigger this listener. Please find below code for more clarification:

Here I am overriding onKey Method which will return a false value if press key is not “Enter” Else it will clear text of Edit text as empty.

For creating AsyncTask with a specific interval, we can use a Handler. A Handler is a safe option because we dont need an extra thread to keep tracking when firing the event.

When we launch any android application it will create a thread which called the Main thread, this thread is handling all the UI event handling so it is also called as UI Thread. A Handler is also a Thread which is running on Main Thread. A Handler allows you to send and process Message and Runnable objects associated with a threads MessageQueue. A Handler can be used to schedule messages or runnable to executed at some point in the future. You can send a message using Handler

In Android, we have many ways to store user data. SharedPreference is a class that allows us to save and retrieve user data in the form of Key and Values. If you kill your application still data will be saved in the shared preference. It will store data in an XML file. For using shared preference we need to create an instance of the getSharedPreferences method. This method is taking two parameters:

In Android application when we need to display a message to the user with to warn him with a button like “Ok” and “Cancel” we are using Alert Dialog Box.

Android Alert Dialog is built with the use of three fields: Title, Message area, Action Button. The code for creating an Alert Dialogue box is mention below:

In android application when user long press on any content it will show an option to perform action this can be done using Context Menu. In your scenario, if user long presses on any contact we can show him a context menu with two options “MakeCall” and “Send SMS”. Please find below code for check how to implement a Context menu in our application:

For adding context menu in our application we need register View who is going to display data at a long press on it. We will create registerForContextMenu(View) for register view in our activity and we need to override onCreateContextMenu() in our activity for displaying option to a user when the view has been long press by the user. In our scenario, Listview is having a list of contact so we will register Listview here. When user long press on any contact it call onCreateContaxtMenu method and show option like MakeCall and SendSMS. Please find below code for more detail:

When we need to display simple popup message to the user without interaction then we are creating Toast Message. But you want to display some popup message with Action then we need to create SnackBars. In our scenario we will create a SnakBars with one button “UnDo” and it will display a message to the user “Text has been send, do you want to undo?”. Please follow the below code for more detail:

Notification is kind of short message that is used to post from an application for giving information that some event has been happening if the application is still not running in the background.

From the Oreo, a new concept has come name as Notification Chanel. This is using for grouping notification based on behavior. So before creating any notification we need to create Notification Chanel at the application level and need to provide its id in Manifest file.

For creating any notification we need to create an object of NotificationCompact.Builder. We can define all the components of Notification like title, ,duration etc by calling setters on the builder object. We can note that we pass a string as parameter to the NotificationCompact.Builder constructor, this string is the Notification Channel ID which means that this notification will now be a part of that particular channel.

At last we need to call NotificationManager object.and we will display our notification using notify() method.

For adding action in Notification we need to specify action. When user click on notification it will open an activity in your app that corresponds to the notification.

To do so, we will specify a content intent defined with a PendingIntent object and pass it to setContentIntent().

In “Contact Us” activity I will create one button name as “Send Email”. Once the user clicks on this button it calls Implicit Intent with Action_Send and we will try to send an email with a specific address. Please find my below code for sending an email to a user with an email address” [email protected]”.

In “ContactUs” Activity I will add one more button for send SMS. When user will click on this button it will call Implicit Intent with Action_View. But for sending SMS we need to add permission in our manifest.xml file. I have written below code for sending SMS in number “111-1111-111”.

We need to create two Spinner control for our activity name as State and Country. This spinner control will display from the adapter. State spinner adapter changes depending on County spinner adapter.

I have written below code to displaying data in Adapter . Please find below step for displaying spinner control:

In Android when we have to perform the long-running operation we can create Async Task to Intent Service.

In AsyncTask, it will create one background thread where the long-running operation will execute and after task result will update in Main Thread.

In Intent Service we can also do the operation but it is running in the background and it will not update UI in Main Thread. if you want to download and cache maps, you may want to call an IntentService so the user doesnt have to be looking at the app for it to download. Likewise, if youre sending data to your server, an IntentService is extremely helpful in this regard because you can start and forget.

As a conclusion, we can say AsyncTask is meant for short tasks that have to communicate with the main thread. IntentService is meant for long tasks that dont have to communicate with the main thread.

When we will try to display our current location in google map android is giving us one api to use the name as google map api.

For displaying the last location we need to override one method name as getLastLocation(). The getLastLocation() method returns a task that we can use to get a Location object with the latitude and longitude coordinates of a geographic location. Sometimes it happens when the location object may be null. There are below situations when we will get null from getLastLocation() method:

The first method is called onCreate(), which fires when the system first creates the activity. On activity creation, the activity enters the Created state.

The last method is guaranteed called ‘onPause()’. The system calls this method as the first indication that the user is leaving your activity (though it does not always mean the activity is being destroyed), but you should save you work/variables/state here. Other methods e.g. onStop, onDestroy may be called or not depends on the system.

They specify which application will satisfy the intent, by supplying either the target apps package name or a fully-qualified component class name.For example, to start a component in your own app, because you know the class name of the activity or service you want to start. For example, you might start a new activity within your app in response to a user action, or start a service to download a file in the background.

They do not name a specific component, but instead declare a general action to perform, which allows a component from another app to handle it. For example, if you want to show the user a location on a map, you can use an implicit intent to request that another capable app show a specified location on a map.

Using stopService() that a given application service will be stopped. If the service is not running, nothing happens. Otherwise, it is stopped. Note that calls to startService() are not counted — this stops the service no matter how many times it was started. Using stopSelf() is same as stopService() but used within the service to indicate system to stop itself.

The main difference between FragmentPagerAdapter and FragmentStatePagerAdapter is FragmentPagerAdapter stores the whole fragment in memory, and If we used a large amount of Fragment in ViewPager it will increase memory while FragmentStatePagerAdapter only stores the savedInstanceState of fragments, and destroys all the fragments when they lose focus.

FragmentPagerAdapter stores the previous data which is fetched from the adapter while FragmentStatePagerAdapter takes the new value from the adapter every time it is executed. Lets take an example of Book Reader application here. I will use FragmentStatePagerAdapter and if I am creating an application which will store heavy data, then I will use FragmentPagerAdapter.

Fused location provider tries to get the best possible location which is certainly the location data from GPS. If you want location from your mobile network put the following permission in your manifest.

The fused location provider is one of the location APIs in Google Play services. It manages the underlying location technology and provides a simple API so that you can specify requirements at a high level, like high accuracy or low power. It also optimizes the devices use of battery power.

I would advise MVVM, it is the pattern of the future. And it is the only architecture that can give you full testing without dependencies. Once you get your head around the data-binding concept, it is super easy. In MVVM we are using Android Architecture Components. There LiveData and ViewModel are the main components which will help in resolving the view dependency.

LiveData is an observable data holder class which is Lifecycle state of the Activity or Fragment. And ViewModel is like the state representation of UI which stores and manages UI-related data in a lifecycle conscious way. It will also save data when screen orientation changed.

When you need to execute some background work fast and need a guarantee of that execution, create WorkerManager. Work manager APIs go beyond the only current state of the task and allows tasks to return data in key-value format. We are using LiveData to return data and state of Work. By using WorkManager, our activity can observe livedata and it will get notified whenever the task is finished.

For creating WorkManager, we need to create one subclass of the Worker class. This class has one abstract method called doWork(). As the name suggests, you need to perform the work you want to do in the background. This method will be called in the background/worker thread. Write a program to perform the task in this method.

In return, you have to return WorkerResult. Returning WorkerResult.SUCCESS indicates that the task you performed completed successfully. Returning WorkerResult.RETRY tells WorkManager to retry the work again. Returning WorkerResult.FAILURE indicates one or more errors occurred.

By using LiveData, we can Observe activity lifecycle method, so livedata will not trigger the change method if view is destroyed. There are many advantages of LiveData

Notification Channels. Notification Channels allow us to separate notifications into different groups/categories. Basically, Notification Channel is designed for User. They can get full control of what they want to be notified about. If they don’t want any notification they can specifically turn off notifications for a certain channel. They can also specify importance as well as the preferred sound for a particular category of notifications and determine whether or not to override Do not disturb

The NotificationChannel constructor requires us to specify the channel_id and channel_name strings. The Importance argument is an int which specifies the level of interruption by the notification.

A toast can be displayed on the screen is defined by a flag as Duration. We can set duration Short or Long. The value for Short is 2.0 second and value for Long is 3.5 Second.

You can not directly change the duration of Toast Message which is showing in the show() method. But there is a workaround. You can use CountDownTimer Class or Handler Class to increase display time of Toast.

For sharing data from one application to another application we are using Content Provider in android. Other application can access data from Content Provider using the provider client object. These provider client object providing an interface between application to access data and handle inter-process communication. Content Provider is saving data in the form of Tables. These tables are having the same schema as relational database tables.

To access the data from the content provider, we use the ContentResolver client object. ContentResolver provides basic methods related to database storage. ContentResolver object and Content Provider objects are handling interprocess communication between application. The ContentResolver methods provide the basic create, retrieve, update, and delete functions of persistent storage.

For protecting the privacy of an Android user we are using Permission concept in android. When the application is trying to access user data like contact, Gallery they requesting permission. Depending on the feature, the system might grant the permission automatically or might prompt the user to approve the request

An Intent object carries information that the Android system uses to determine which component to start. The Intent object contains information which is used either from the components that receive that intent or the Android system itself.

We are defining the Intent Filter in Manifest File. We can set the type of intents to accept perform some action using these elements:

For checking the status of BatteryLow and sending information to the user, we can create a BroadCast Receiver who will send a triggers battery Low notification that you see on your mobile screen.

A Broadcast Receiver is an Android component which allows you to register for system or application events. Once Event occur it will Broadcast message to the user.

findViewById is a method that finds the view from the layout resource file that is attached to the current Activity. This method refers to a view with requested viewId. is already created and exists. If you do not call findViewById for some view, then nothing changes.

There is a disadvantage of findViewById() returns a View if it exists in the layout you provided in setContentView(), otherwise it returns null at runtime. There is no compile time check for this method.

We have to add data<> tag before the UI view root within the layout tag. It will bind Object . data<> element can have multiple variable<> tag within it. Those are using to describe a property that can be used within the layout.

If you want to send data from fragment to another Fragment we need to use an interface. Intents are only usable for sending data on an Activity level. To pass data between fragments we need to create our own interfaces.

In onAttach() lifecycle method , the fragment implement the Interface logic and it will call Interface methods to communicate with an activity.

The activity that hosts fragment must implement the interface For receiving callback events from Fragment class. First host activity creates an instance of fragment using findFragmentById method then it can deliver a message to fragment directly by calling the fragments public methods.

In, we can send information from one activity to another and vice-versa using startActivityForResult() method. The android startActivityForResult method requires a result from the second activity. For that, we need to override the onActivityResult method that is invoked automatically when the second activity returns a result.

In Activity B we will send someResultCode to Activity A, which will handle it with the onActivityResult and send it back again with setResult(…) finish();

In Android, service is a component which is like activity and running in the background. Once it is started, it will run in the background even if the application goes background. But from Android O, they introduce a new concept that a user should know what task is running in the background and it also should show the notification to user with some action buttons so that the user can interact with the ongoing operation if they want. So for this, we have the best approach called as an Android Foreground Service. This foreground service is giving notification to the user that task is running in the background, for example, playing music or downloading files from the internet. And if the user wants to stop that service, then he can stop using Notification.

So to create foreground service you have to use NotificationManager.startServiceInForeground() method to send a notification to the user that the Background Service is running and if he wants he can stop it.

Menu Item is part of the menu.xml file. When we want to add a menu in-out activity we need to method OnCreateOptionMenu(Menu menu). But If you want to add any Menu Item at run time then the system calls your activity’s onPrepareOptionsMenu() method. this method passes currently exist menu object to modify the menu item. Please follow the below code for more detail:

In Android, applications cannot access the data of other application. For sharing data between two applications, we need to provide permissions. Here we have to provide permission on both side:

There are many scenarios where we want other application can read our application data but can not change it. Or sometimes we are providing them access to modify our application data.

In your scenario, we can provide read permission “android:readPermission” attribute in the provider so that Google calendar read data from Gmail application.

When we need to create any custom view in Android, we will extend our class from the View parent class. In this scenario, as we need to create a custom Text view so we will create a subclass of TextView class. And then we can our Custom textview in a layout.xml file.

We need to define our custom textview in ‘res’layout folder and write the code like as shown below.

In your scenario, we have to design a login screen in the application where the login activity is having two control an email and a password. An email we want to display autofill data based on the user email address. We will use AutoCompleteTextView in our layout to display email and password data.

What we can do here in our Java activity we can create an object of Account Manager and we load the user accounts through the AccountManager.

As some accounts may not have an email address linked to them, we filter them and keep only the ones who match an email regex. We also use a Set to remove the duplicates. Now we just have an array of Strings as the data source and we just bind via an ArrayAdapter the list of an email address. Now we can display data of email and password in autocomplete text view. One we need to remember before running this code we need to add below permission in our manifest file.

ADB is an Android device bridge command-line tool. Basically, we are using ABD for controlling your device over USB from a computer and we can copy files back and forth, install and uninstall apps, run shell commands.

ADB lets you modify your device and its software using the PC command line. Before connecting with ADB we need to remember to put your device in USB debugging mode. This can be found by navigating to Menu>Settings>Applications>Development and checking the box for USB debugging. Without doing this, your PC won’t recognize your device.

ADB is part of Android SDK, from here we can download it. You can connect it using the Terminal window of Android Studio.

Once ADB, install we can all device connected with your machine in this terminal. If your device does not show up, you may have an issue with your drivers. We have many Linux command here to control device. Some commands are:

In Android we have one draw back with Frame layout, when you have multiple child view in Frame layout, they used overlap each other. For resolving this problem we can use CoordinatorLayout. In Coordinator Layput has additional level of control over it’s child views. It can coordinates the animations and transitions of child views with one another.Please find below code where we are adding child view in coordinator view.

For doing some job like Application Update or where you want your CPU keeps running before the device go to sleep so we can use Power Manager service. This service will give you one feature like WakeLock that allows our application to control the power state. if we need to want to keep the screen on in our activity, we need to use FLAG_KEEP_SCREEN_ON. As mention below:

In Android, it is very normal to found memory leak scenario as many tasks are running in the background thread. Many time if Activity or fragment who start background thread using Async task is killed, Still the background thread will be alive.

We can handle this problem by calling the method removeCallbacksAndMessages on the handler in the onDestroy method of the activity.

If we cancel the task, we will not cause a memory leak. We can also solve that problem by constructing the new Java file with a context.getApplicationContext() instead of normal getContext / this (Activity). Then it will not be tied to the activity but to the application. We wont be able to access the dialog in onPostExecute(). Instead, we can use a callback to a listener if we want.

Here we have to create an application that schedules a task and send a notification. For that, we need to execute a particular job daily at a specific time defined by the user. We can do it using the AlarmManager in android. Android has a built-in AlarmManager class which makes scheduling tasks. AlarmManager provides access to system-level alarm services. This gives a way to perform any operations outside the lifetime of your application. So we can trigger events or actions even when your application is not running. Step to schedule task is mentioned below:

There is no direct way to terminate a thread but using the two following ways it can be done.

MVVM stands for Model-View-ViewModel. Android applications built using MVVM are more robust, fast, scalable and very less prone to memory leaks. In MVVM ViewModel is the key between View and Model.

The important key point about MVVM is that View has reference to the ViewModel but not in reverse and that makes the application’s UI-Components related memory leak-proof. Each View may have a dedicated ViewModel or may be shared by multiple in case of fragments to enable sharing data cross fragments of an activity. MVVM is a more suitable candidate for automated testing.

It stands for Android Run Time. ART is used for running Android applications. It uses AOT (Ahead Of Time) compilation on the device. When an APK is getting installed on the Android device, the .dex files from the APK file will be converted to processor’s native instructions set/machine code (.art extension) and that will be stored in the app’s runtime cache directory on the device’s internal storage. This will make installation little bit longer and take more space on the device storage but it makes apps run much faster, less battery consumption, robots application debugging support and better user experience.

The recommended way going forward is using WorkManager APIs, that makes it easy to specify deferrable, asynchronous tasks and when they should run under the circumstances you choose, or recurring tasks that run at a specified interval. Internally WorkManager might use JobScheduler, Firebase-JobDispatcher, Executor, and AlarmManager for running the task.

Android is a ‘Linux based software stack’ created for a wide array of devices and form factors. It is open source. It has layers of major components from bottom to top as follows…

It is the foundation for any Android application. It will be in app module’s src/main/ directory for Android Studio projects. This file contains information of application package, including components of the application such as activities, services, broadcast receivers, content providers etc. It performs some other tasks also: It is responsible to protect the application to access any protected parts by provision of permissions.

In Android, UI is representing as an Activity. Single Screen in an application represents as Activity while Fragments are reusable UI with business logic. Activity is a collection of Screen. In android application, Fragments are using in Navigation Drawer in our entire screen. You can also use fragment to display Google Map on screen.

Android OS provides back stack function for Activity, it also provides back stack function for Fragment. If you add one Fragment into the back stack, when you press the android device back menu, you can find the Fragment that is saved in back stack popup. Until all saved Fragments in back stack popup, then the activity will exit.

We have to create “FragmentTransaction objects on the back stack and when the user presses the Back button, the “FragmentManager pops the most recent transaction off the back stack and performs the reverse action.

In Android when we want to share data between two applications we are using Content Provider. It has a complete mechanism to share data between applications. It will also provide security while sharing data from one application to another application. For getting data from any Content Provider you need to create Content Resolver. For Creating Content Resolver, you need to call Activity’s getContentResolver method.

For Modifying data from Content Provider, you can invoke the basic method of Content Resolver like insert, delete, update and query. These operations are the same as the SQLite DB Operation.

For this, we can modify our build Gradle file of the application. In Gradle file we will add code for adding build type and build flavour like below:

When you need to send Object from one activity to another activity, we are using two techniques: 1. Serialization and 2. Parcelable. In other case passing data from one activity to another activity, we are using Intent. Parcelable is a faster approach compared to Serialization because it is using Android SDK.

Launch mode is an instruction for Android OS which specifies how the activity should be launched. It instructs how any new activity should be associated with the current task.

So in your scenario When using launchMode=”singleInstance”, there are two things that we need to remember:

As such, an Activity with launchMode of singleInstance will always be isolated in its own task. There wont be another Activity inside of that task.

From what happened here, you have one a task that stores the launchMode=”standard” Activity A and Activity C. Activity B is in its own task. Activity D is in its own task.

Also, Activity D definitely wont be in the same task as Activity B because Activity Bs task is meant only for Activity B due to launchMode=”singleInstance”.

In Android Service is something that is running in the background. In a simple way, we can say that a background service is same as an Activity. The only difference is it doesn’t have UI. A background Service can be started by calling the startService method in your Activity. we need to create an explicit Intent, which means that you either make a reference to the Service’s class, or you include the package name of your app in the Intent. For example:

There is one drawback with Service is that it is running on Main Thread so you can not assign any long running operation to service. But if you want to run some long running operation in the background, you should use IntentService.

IntentService is creating its own Worker Thread which is running separately from the Main Thread. Examples for its usage would be to download certain resources from the Internet. For creating Intent Service you need to create a service class by extending IntentService and implementing onHandleIntent() method.

In Intent Service we can start service by calling startService method passing intent which identifies the service. We can call startService any number of times, but in the background it will create only one instance of intent service and all requests are queued and processed in separate work thread. We don’t need to worry about calling stopService, as IntentService stops itself when there are no requests to serve.

In Android Sticky Intent is a type of Intent who will communicate between Service and Function. Sticky Intent is using with Sticky Broadcast that’s why they are calling as StickyIntent. In simple language, we can say that StickyIntent is stick with till Broadcast is not completed its job this intent will be present and return data of registerReceiver() method and will be re-delivered or re-broadcasted to the future requests from any broadcast receivers. We have one more advantage of Sticky Intent that Sticky Broadcast will replace the previous instance of the sticky broadcast and save your application from memory leak.

For example, if we need to send a notification for Low status of Battery, we will create a sticky broadcast sent via the operating system is ACTION_BATTERY_CHANGED. As soon broadcast that action we will get the Intent with data. For this first, we need to add special permission in the manifest file that allows an application to broadcast sticky intents.

View is a basic building block of UI (User Interface) in android. A view is a small rectangular box which responds to user inputs. For example, a Text View is used to display some text to the user that is a subclass of View. In Android, we are using many View subclass like EditText, Button, CheckBox, Radio Button, View, DatePicker etc.

ViewGroup is an invisible container of other child view. ViewGroup is a special kind of view which is extended from View as its base class. ViewGroup is the base class for layouts. Viewgroups can contain other views in it. For example LinearLayout, it is a group of many views those are arranging in Linear or Veridical way. In Android, we have other layouts as well like Relative Layout, Table Layout, Frame Layout etc.

The Recycler view is the most advanced component of Android. We can also say that RecyclerView is the most advanced form of ListView. Recycler view is containing new feature like ViewModel, Adapter, LayoutManager, SoothScroller. There are many differences many difference between listview and RecyclerView.

In ListView we cannot do horizontal scrolling while in RecyclerView we have both option Horizontal and Vertical Scrolling.

In RecyclerView class, it is using a ViewHolder object which is used by the adapter to bind ViewHolder with a position while in ListView we are not using ViewHolder.

In ListView, if the data set is changed you have to call the notifyDataSetChanged method of the underlying adapter to refresh data. While in a RecyclerView adapter, if a single item or a range of items have changed, there are methods to notify the change accordingly like notifyItemChanged and notifyItemRangeChanged.

Having rotated the device, the following state change sequence should appear Clearly this has resulted in the activity being destroyed and re-created. To save the state information override onSaveInstanceState() method and add key-value pairs to the Bundle object. It will save data in the event that your activity is destroyed unexpectedly. This method gets called before onStop(). To get saved from an activity state, we are using method onRestoreInstanceState.

The first step in extending the StateChange application is to make sure that the text entered by the user is extracted from the EditText component within the onSaveInstanceState() method of the StateChangeActivity activity and then saved as a key-value pair into the Bundle object.

Alternately, use the onRestoreInstanceState( ) method to extract saved state from the Bundle and restore it into new instances of the activity. The onRestoreInstanceState( ) method is another callback lifecycle method that is also rarely seen in the activity lifecycle diagrams. The onRestoreInstanceState( ) method is automatically invoked by Android between the onStart( ) and the onResume( ) lifecycle methods.

You can do it by setting an OnKeyListener on your EditText. This is only useful for hardware keyboards. A software input method has no obligation to trigger this listener. Please find below code for more clarification:

Here I am overriding onKey Method which will return a false value if press key is not “Enter” Else it will clear text of Edit text as empty.

For creating AsyncTask with a specific interval, we can use a Handler. A Handler is a safe option because we dont need an extra thread to keep tracking when firing the event.

When we launch any android application it will create a thread which called the Main thread, this thread is handling all the UI event handling so it is also called as UI Thread. A Handler is also a Thread which is running on Main Thread. A Handler allows you to send and process Message and Runnable objects associated with a threads MessageQueue. A Handler can be used to schedule messages or runnable to executed at some point in the future. You can send a message using Handler

In Android, we have many ways to store user data. SharedPreference is a class that allows us to save and retrieve user data in the form of Key and Values. If you kill your application still data will be saved in the shared preference. It will store data in an XML file. For using shared preference we need to create an instance of the getSharedPreferences method. This method is taking two parameters:

In Android application when we need to display a message to the user with to warn him with a button like “Ok” and “Cancel” we are using Alert Dialog Box.

Android Alert Dialog is built with the use of three fields: Title, Message area, Action Button. The code for creating an Alert Dialogue box is mention below:

In android application when user long press on any content it will show an option to perform action this can be done using Context Menu. In your scenario, if user long presses on any contact we can show him a context menu with two options “MakeCall” and “Send SMS”. Please find below code for check how to implement a Context menu in our application:

For adding context menu in our application we need register View who is going to display data at a long press on it. We will create registerForContextMenu(View) for register view in our activity and we need to override onCreateContextMenu() in our activity for displaying option to a user when the view has been long press by the user. In our scenario, Listview is having a list of contact so we will register Listview here. When user long press on any contact it call onCreateContaxtMenu method and show option like MakeCall and SendSMS. Please find below code for more detail:

When we need to display simple popup message to the user without interaction then we are creating Toast Message. But you want to display some popup message with Action then we need to create SnackBars. In our scenario we will create a SnakBars with one button “UnDo” and it will display a message to the user “Text has been send, do you want to undo?”. Please follow the below code for more detail:

Notification is kind of short message that is used to post from an application for giving information that some event has been happening if the application is still not running in the background.

From the Oreo, a new concept has come name as Notification Chanel. This is using for grouping notification based on behavior. So before creating any notification we need to create Notification Chanel at the application level and need to provide its id in Manifest file.

For creating any notification we need to create an object of NotificationCompact.Builder. We can define all the components of Notification like title, ,duration etc by calling setters on the builder object. We can note that we pass a string as parameter to the NotificationCompact.Builder constructor, this string is the Notification Channel ID which means that this notification will now be a part of that particular channel.

At last we need to call NotificationManager object.and we will display our notification using notify() method.

For adding action in Notification we need to specify action. When user click on notification it will open an activity in your app that corresponds to the notification.

To do so, we will specify a content intent defined with a PendingIntent object and pass it to setContentIntent().

In “Contact Us” activity I will create one button name as “Send Email”. Once the user clicks on this button it calls Implicit Intent with Action_Send and we will try to send an email with a specific address. Please find my below code for sending an email to a user with an email address” [email protected]”.

In “ContactUs” Activity I will add one more button for send SMS. When user will click on this button it will call Implicit Intent with Action_View. But for sending SMS we need to add permission in our manifest.xml file. I have written below code for sending SMS in number “111-1111-111”.

We need to create two Spinner control for our activity name as State and Country. This spinner control will display from the adapter. State spinner adapter changes depending on County spinner adapter.

I have written below code to displaying data in Adapter . Please find below step for displaying spinner control:

In Android when we have to perform the long-running operation we can create Async Task to Intent Service.

In AsyncTask, it will create one background thread where the long-running operation will execute and after task result will update in Main Thread.

In Intent Service we can also do the operation but it is running in the background and it will not update UI in Main Thread. if you want to download and cache maps, you may want to call an IntentService so the user doesnt have to be looking at the app for it to download. Likewise, if youre sending data to your server, an IntentService is extremely helpful in this regard because you can start and forget.

As a conclusion, we can say AsyncTask is meant for short tasks that have to communicate with the main thread. IntentService is meant for long tasks that dont have to communicate with the main thread.

When we will try to display our current location in google map android is giving us one api to use the name as google map api.

For displaying the last location we need to override one method name as getLastLocation(). The getLastLocation() method returns a task that we can use to get a Location object with the latitude and longitude coordinates of a geographic location. Sometimes it happens when the location object may be null. There are below situations when we will get null from getLastLocation() method:

The first method is called onCreate(), which fires when the system first creates the activity. On activity creation, the activity enters the Created state.

The last method is guaranteed called ‘onPause()’. The system calls this method as the first indication that the user is leaving your activity (though it does not always mean the activity is being destroyed), but you should save you work/variables/state here. Other methods e.g. onStop, onDestroy may be called or not depends on the system.

They specify which application will satisfy the intent, by supplying either the target apps package name or a fully-qualified component class name.For example, to start a component in your own app, because you know the class name of the activity or service you want to start. For example, you might start a new activity within your app in response to a user action, or start a service to download a file in the background.

They do not name a specific component, but instead declare a general action to perform, which allows a component from another app to handle it. For example, if you want to show the user a location on a map, you can use an implicit intent to request that another capable app show a specified location on a map.

Using stopService() that a given application service will be stopped. If the service is not running, nothing happens. Otherwise, it is stopped. Note that calls to startService() are not counted — this stops the service no matter how many times it was started. Using stopSelf() is same as stopService() but used within the service to indicate system to stop itself.

The main difference between FragmentPagerAdapter and FragmentStatePagerAdapter is FragmentPagerAdapter stores the whole fragment in memory, and If we used a large amount of Fragment in ViewPager it will increase memory while FragmentStatePagerAdapter only stores the savedInstanceState of fragments, and destroys all the fragments when they lose focus.

FragmentPagerAdapter stores the previous data which is fetched from the adapter while FragmentStatePagerAdapter takes the new value from the adapter every time it is executed. Lets take an example of Book Reader application here. I will use FragmentStatePagerAdapter and if I am creating an application which will store heavy data, then I will use FragmentPagerAdapter.

Fused location provider tries to get the best possible location which is certainly the location data from GPS. If you want location from your mobile network put the following permission in your manifest.

The fused location provider is one of the location APIs in Google Play services. It manages the underlying location technology and provides a simple API so that you can specify requirements at a high level, like high accuracy or low power. It also optimizes the devices use of battery power.

I would advise MVVM, it is the pattern of the future. And it is the only architecture that can give you full testing without dependencies. Once you get your head around the data-binding concept, it is super easy. In MVVM we are using Android Architecture Components. There LiveData and ViewModel are the main components which will help in resolving the view dependency.

LiveData is an observable data holder class which is Lifecycle state of the Activity or Fragment. And ViewModel is like the state representation of UI which stores and manages UI-related data in a lifecycle conscious way. It will also save data when screen orientation changed.

When you need to execute some background work fast and need a guarantee of that execution, create WorkerManager. Work manager APIs go beyond the only current state of the task and allows tasks to return data in key-value format. We are using LiveData to return data and state of Work. By using WorkManager, our activity can observe livedata and it will get notified whenever the task is finished.

For creating WorkManager, we need to create one subclass of the Worker class. This class has one abstract method called doWork(). As the name suggests, you need to perform the work you want to do in the background. This method will be called in the background/worker thread. Write a program to perform the task in this method.

In return, you have to return WorkerResult. Returning WorkerResult.SUCCESS indicates that the task you performed completed successfully. Returning WorkerResult.RETRY tells WorkManager to retry the work again. Returning WorkerResult.FAILURE indicates one or more errors occurred.

By using LiveData, we can Observe activity lifecycle method, so livedata will not trigger the change method if view is destroyed. There are many advantages of LiveData

Notification Channels. Notification Channels allow us to separate notifications into different groups/categories. Basically, Notification Channel is designed for User. They can get full control of what they want to be notified about. If they don’t want any notification they can specifically turn off notifications for a certain channel. They can also specify importance as well as the preferred sound for a particular category of notifications and determine whether or not to override Do not disturb

The NotificationChannel constructor requires us to specify the channel_id and channel_name strings. The Importance argument is an int which specifies the level of interruption by the notification.

A toast can be displayed on the screen is defined by a flag as Duration. We can set duration Short or Long. The value for Short is 2.0 second and value for Long is 3.5 Second.

You can not directly change the duration of Toast Message which is showing in the show() method. But there is a workaround. You can use CountDownTimer Class or Handler Class to increase display time of Toast.

For sharing data from one application to another application we are using Content Provider in android. Other application can access data from Content Provider using the provider client object. These provider client object providing an interface between application to access data and handle inter-process communication. Content Provider is saving data in the form of Tables. These tables are having the same schema as relational database tables.

To access the data from the content provider, we use the ContentResolver client object. ContentResolver provides basic methods related to database storage. ContentResolver object and Content Provider objects are handling interprocess communication between application. The ContentResolver methods provide the basic create, retrieve, update, and delete functions of persistent storage.

For protecting the privacy of an Android user we are using Permission concept in android. When the application is trying to access user data like contact, Gallery they requesting permission. Depending on the feature, the system might grant the permission automatically or might prompt the user to approve the request

An Intent object carries information that the Android system uses to determine which component to start. The Intent object contains information which is used either from the components that receive that intent or the Android system itself.

We are defining the Intent Filter in Manifest File. We can set the type of intents to accept perform some action using these elements:

For checking the status of BatteryLow and sending information to the user, we can create a BroadCast Receiver who will send a triggers battery Low notification that you see on your mobile screen.

A Broadcast Receiver is an Android component which allows you to register for system or application events. Once Event occur it will Broadcast message to the user.

findViewById is a method that finds the view from the layout resource file that is attached to the current Activity. This method refers to a view with requested viewId. is already created and exists. If you do not call findViewById for some view, then nothing changes.

There is a disadvantage of findViewById() returns a View if it exists in the layout you provided in setContentView(), otherwise it returns null at runtime. There is no compile time check for this method.

We have to add data<> tag before the UI view root within the layout tag. It will bind Object . data<> element can have multiple variable<> tag within it. Those are using to describe a property that can be used within the layout.

If you want to send data from fragment to another Fragment we need to use an interface. Intents are only usable for sending data on an Activity level. To pass data between fragments we need to create our own interfaces.

In onAttach() lifecycle method , the fragment implement the Interface logic and it will call Interface methods to communicate with an activity.

The activity that hosts fragment must implement the interface For receiving callback events from Fragment class. First host activity creates an instance of fragment using findFragmentById method then it can deliver a message to fragment directly by calling the fragments public methods.

In, we can send information from one activity to another and vice-versa using startActivityForResult() method. The android startActivityForResult method requires a result from the second activity. For that, we need to override the onActivityResult method that is invoked automatically when the second activity returns a result.

In Activity B we will send someResultCode to Activity A, which will handle it with the onActivityResult and send it back again with setResult(…) finish();

In Android, service is a component which is like activity and running in the background. Once it is started, it will run in the background even if the application goes background. But from Android O, they introduce a new concept that a user should know what task is running in the background and it also should show the notification to user with some action buttons so that the user can interact with the ongoing operation if they want. So for this, we have the best approach called as an Android Foreground Service. This foreground service is giving notification to the user that task is running in the background, for example, playing music or downloading files from the internet. And if the user wants to stop that service, then he can stop using Notification.

So to create foreground service you have to use NotificationManager.startServiceInForeground() method to send a notification to the user that the Background Service is running and if he wants he can stop it.

Menu Item is part of the menu.xml file. When we want to add a menu in-out activity we need to method OnCreateOptionMenu(Menu menu). But If you want to add any Menu Item at run time then the system calls your activity’s onPrepareOptionsMenu() method. this method passes currently exist menu object to modify the menu item. Please follow the below code for more detail:

In Android, applications cannot access the data of other application. For sharing data between two applications, we need to provide permissions. Here we have to provide permission on both side:

There are many scenarios where we want other application can read our application data but can not change it. Or sometimes we are providing them access to modify our application data.

In your scenario, we can provide read permission “android:readPermission” attribute in the provider so that Google calendar read data from Gmail application.

When we need to create any custom view in Android, we will extend our class from the View parent class. In this scenario, as we need to create a custom Text view so we will create a subclass of TextView class. And then we can our Custom textview in a layout.xml file.

We need to define our custom textview in ‘res’layout folder and write the code like as shown below.

In your scenario, we have to design a login screen in the application where the login activity is having two control an email and a password. An email we want to display autofill data based on the user email address. We will use AutoCompleteTextView in our layout to display email and password data.

What we can do here in our Java activity we can create an object of Account Manager and we load the user accounts through the AccountManager.

As some accounts may not have an email address linked to them, we filter them and keep only the ones who match an email regex. We also use a Set to remove the duplicates. Now we just have an array of Strings as the data source and we just bind via an ArrayAdapter the list of an email address. Now we can display data of email and password in autocomplete text view. One we need to remember before running this code we need to add below permission in our manifest file.

ADB is an Android device bridge command-line tool. Basically, we are using ABD for controlling your device over USB from a computer and we can copy files back and forth, install and uninstall apps, run shell commands.

ADB lets you modify your device and its software using the PC command line. Before connecting with ADB we need to remember to put your device in USB debugging mode. This can be found by navigating to Menu>Settings>Applications>Development and checking the box for USB debugging. Without doing this, your PC won’t recognize your device.

ADB is part of Android SDK, from here we can download it. You can connect it using the Terminal window of Android Studio.

Once ADB, install we can all device connected with your machine in this terminal. If your device does not show up, you may have an issue with your drivers. We have many Linux command here to control device. Some commands are:

In Android we have one draw back with Frame layout, when you have multiple child view in Frame layout, they used overlap each other. For resolving this problem we can use CoordinatorLayout. In Coordinator Layput has additional level of control over it’s child views. It can coordinates the animations and transitions of child views with one another.Please find below code where we are adding child view in coordinator view.

For doing some job like Application Update or where you want your CPU keeps running before the device go to sleep so we can use Power Manager service. This service will give you one feature like WakeLock that allows our application to control the power state. if we need to want to keep the screen on in our activity, we need to use FLAG_KEEP_SCREEN_ON. As mention below:

In Android, it is very normal to found memory leak scenario as many tasks are running in the background thread. Many time if Activity or fragment who start background thread using Async task is killed, Still the background thread will be alive.

We can handle this problem by calling the method removeCallbacksAndMessages on the handler in the onDestroy method of the activity.

If we cancel the task, we will not cause a memory leak. We can also solve that problem by constructing the new Java file with a context.getApplicationContext() instead of normal getContext / this (Activity). Then it will not be tied to the activity but to the application. We wont be able to access the dialog in onPostExecute(). Instead, we can use a callback to a listener if we want.

Here we have to create an application that schedules a task and send a notification. For that, we need to execute a particular job daily at a specific time defined by the user. We can do it using the AlarmManager in android. Android has a built-in AlarmManager class which makes scheduling tasks. AlarmManager provides access to system-level alarm services. This gives a way to perform any operations outside the lifetime of your application. So we can trigger events or actions even when your application is not running. Step to schedule task is mentioned below:

Android is a software package and Linux based OS for mobile devices such as computers, tablets, and smartphones. Is developed by Google and later the OHA (Open Handset Alliance). The goal of the Android project is to create a successful real-world product that improves the mobile experience for end users. For today there are many codes names of Android such a Lollipop, KitKat, Jelly Bean, etc.

Today Android become the indisputable leader of the global smartphone market share. This is mainly due to an increase in the use of smartphones in Countries like India, USA, Brazil, China and many more. One of the important features of Android is the integration of Google products and services.

It’s the best time for you to launch a career in Android development. There’s a healthy supply of jobs, demand for Android apps. The expansion is increasing the demand for mobile application developers, currently, have lots of opportunities for employment. 2018 has been a game the dynamic year for the smartphone market.

So, if you are planning to start your career in Android development then you need to be well prepared with all the possible Android interview questions which could be asked in an Android interview. There are several complicated Android developer interview questions you might come across in the Android interview. This article will equip you to deal with Android interview questions asked in Android developer interviews.

Submitted questions and answers are subjecct to review and editing,and may or may not be selected for posting, at the sole discretion of Knowledgehut. Name Email Enter your Question Enter your Answer

All fields are required, by clicking the button you agree with the Terms and Conditions of knowledgehut.LLCs Privacy Policy

All fields are required, by clicking the button you agree with the Terms and Conditions of knowledgehut.LLCs Privacy Policy

TOP 15 MVVM Interview Questions and Answers 2019 | MVVM Interview Questions | Wisdom Jobs

We help you to choose the right Python career Path at myTectra. Here are the top courses in Python one can select. Learn More →

Commands are used to decouple an object that issues a command from the logic that follows. Many different UI control actions can raise the same command and execute logic using this technique. Copy and cut actions, for example, can both invoke the same command. Better separation of concerns is achieved because the logic that handles the action is decoupled from the control that raises the event, allowing for better separation of concerns.

Android Run Time is what it’s called. Runtime for Android applications is provided by Android Application Runtime (ART). On the device, AOT (Ahead Of Time) compilation is used to compile the code. APK files with.dex extensions are converted to native instructions set/machine code (.art extension) and stored in the app’s runtime cache directory on the device’s internal storage when an APK is installed. It will take a little longer to install and take up more space on the device’s storage, but it will make apps run faster, use less battery power, and provide a better user experience.

MVVM is an abbreviation of the Microsoft design pattern Model-View-ViewModel. “Presentation Model” is Martin Fowler’s specialization of the MVC pattern. Model and ViewModel are the 3 roles of this pattern. As in MVC, View and Model play the same roles. Model-View-Controller (MVVM) views the Model as if it were a special controller for a View. The ViewModel exposes data from the Model to the View and provides action and logic for user requests from the View. This type of abstraction contains the state and behavior of the View.

You need a Value Converter when your target is bound to only one input source, as in the case of text boxes and buttons. As soon as the text box is filled or null, you want to enable or disable the button. String data must be converted to Boolean in this situation. Value Converters make this possible. In order to implement Value Converters, the System must inherit from I Value Converter. Windows. Convert and Convert Back methods are implemented in the data namespace.

Using WPF resources, you can reuse objects and values that are commonly defined. You can set the properties of multiple controls at once using WPF’s resources. You can, for example, use a single resource to set the background property on multiple elements in a WPF application. When defining resources, it’s best to do so at the Window or Page element level. Each element’s child elements are affected by the resources you define for it. The resources defined for the window elements, for example, can be used by the grid element. As an exception to this rule, if you define a resource for a grid component, that resource only applies to the grid element’s child elements

Prepared and maintained by Amit Shekhar who is having experience of taking interviews of many Android developers and cracking interviews of top companies.

  • Tell all the Android application components.Learn from here
  • What is the project structure of an Android Application?Learn from here
  • What is Context? How is it used?Learn from here
  • What is AndroidManifest.xml?Learn from here
  • What is Application class?
    • The Application class in Android is the base class within an Android app that contains all other components such as activities and services. The Application class, or any subclass of the Application class, is instantiated before any other class when the process for your application/package is created.
  • What is Activity and its lifecycle?Learn from here
  • What is the difference between onCreate() and onStart()Learn from here
  • When only onDestroy is called for an activity without onPause() and onStop()?Learn from here
  • Why do we need to call setContentView() in onCreate() of Activity class?Learn from here
  • What is onSavedInstanceState() and onRestoreInstanceState() in activity?
    • onSavedInstanceState() – This method is used to store data before pausing the activity.
    • onRestoreInstanceState() – This method is used to recover the saved state of an activity when the activity is recreated after destruction. So, the onRestoreInstanceState() receive the bundle that contains the instance state information.
  • What is Fragment and its lifecycle.Learn from here
  • What are “launch modes”?Learn from here
  • What is the difference between a Fragment and an Activity? Explain the relationship between the two.Learn from here
  • When should you use a Fragment rather than an Activity?
    • When you have some UI components to be used across various activities
    • When multiple view can be displayed side by side just like viewPager
  • What is the difference between FragmentPagerAdapter vs FragmentStatePagerAdapter?
    • FragmentPagerAdapter: Each fragment visited by the user will be stored in the memory but the view will be destroyed. When the page is revisited, then the view will be created not the instance of the fragment.
    • FragmentStatePagerAdapter: Here, the fragment instance will be destroyed when it is not visible to the user, except the saved state of the fragment.
  • What is the difference between adding/replacing fragment in backstack?Learn from here
  • Why is it recommended to use only the default constructor to create a Fragment?Learn from here
  • How would you communicate between two Fragments?Learn from here
  • What is retained Fragment?
    • By default, Fragments are destroyed and recreated along with their parent Activity’s when a configuration change occurs. Calling setRetainInstance(true) allows us to bypass this destroy-and-recreate cycle, signaling the system to retain the current instance of the fragment when the activity is recreated.
  • What is the purpose of addToBackStack() while commiting fragment transaction?
    • By calling addToBackStack(), the replace transaction is saved to the back stack so the user can reverse the transaction and bring back the previous fragment by pressing the Back button. For more Learn from here
  • What is Dialog in Android?Learn from here
  • What is Toast in Android?Learn from here
  • What the difference between Dialog and Dialog Fragment?Learn from here
  • What is Intent?Learn from here
  • What is an Implicit Intent?Learn from here
  • What is an Explicit Intent?Learn from here
  • What is a BroadcastReceiver?Learn from here
  • What is a LocalBroadcastManager?Learn from here
  • What is the function of an IntentFilter?Learn from here
  • What is a Sticky Intent?
    • Sticky Intents allows communication between a function and a service. sendStickyBroadcast() performs a sendBroadcast(Intent) known as sticky, i.e. the Intent you are sending stays around after the broadcast is complete, so that others can quickly retrieve that data through the return value of registerReceiver(BroadcastReceiver, IntentFilter). For example, if you take an intent for ACTION_BATTERY_CHANGED to get battery change events: When you call registerReceiver() for that action — even with a null BroadcastReceiver — you get the Intent that was last Broadcast for that action. Hence, you can use this to find the state of the battery without necessarily registering for all future state changes in the battery.
  • Describe how broadcasts and intents work to be able to pass messages around your app?Learn from here
  • What is a PendingIntent?
    • If you want someone to perform any Intent operation at future point of time on behalf of you, then we will use Pending Intent.
  • What are the different types of Broadcasts?Learn from here
  • How to run parallel tasks in Java or Android, and get callback when all complete?Learn from here
  • Why should you avoid to run non-ui code on the main thread?Learn from here
  • What is ANR? How can the ANR be prevented?Learn from here
  • What is an AsyncTask(Deprecated in API level 30) ?Learn from here
  • What are the problems in AsyncTask?Learn from here
  • When would you use java thread instead of an AsyncTask?Learn from here
  • What is a Loader? (Deprecated)Learn from here
  • What is the relationship between the life cycle of an AsyncTask and an Activity? What problems can this result in? How can these problems be avoided?
    • An AsyncTask is not tied to the life cycle of the Activity that contains it. So, for example, if you start an AsyncTask inside an Activity and the user rotates the device, the Activity will be destroyed (and a new Activity instance will be created) but the AsyncTask will not die but instead goes on living until it completes.
    • Then, when the AsyncTask does complete, rather than updating the UI of the new Activity, it updates the former instance of the Activity (i.e., the one in which it was created but that is not displayed anymore!). This can lead to an Exception (of the type java.lang.IllegalArgumentException: View not attached to window manager if you use, for instance, findViewById to retrieve a view inside the Activity).
    • There’s also the potential for this to result in a memory leak since the AsyncTask maintains a reference to the Activity, which prevents the Activity from being garbage collected as long as the AsyncTask remains alive.
    • For these reasons, using AsyncTasks for long-running background tasks is generally a bad idea . Rather, for long-running background tasks, a different mechanism (such as a service) should be employed.
    • Note: AsyncTasks by default run on a single thread using a serial executor, meaning it has only 1 thread and each task runs one after the other.
  • Explain Looper, Handler and HandlerThread.Learn from here and from video
  • How does the threading work in Android?Learn from here
  • Android Memory Leak and Garbage CollectionLearn from here
  • How do you handle bitmaps in Android as it takes too much memory?Learn from here and here
  • What is the difference between a regular Bitmap and a nine-patch ?
    • In general, a Nine-patch allows resizing that can be used as background or other size requirements for the target device. The Nine-patch refers to the way you can resize the : 4 corners that are unscaled, 4 edges that are scaled in 1 axis, and the middle one that can be scaled into both axes.
  • Tell about the Bitmap pool.Learn from here
  • How to play sounds in Android?Learn from here
  • How compression is preformed?Learn from here
  • How to persist data in an Android app?Learn from here
  • What is ORM? How does it work?Learn from here
  • How would you preserve Activity state during a screen rotation?Learn from here
  • What are different ways to store data in your Android app?Learn from here
  • Explain Scoped Storage in Android.Learn from here
  • How to encrypt data in Android?Learn from here
  • What is commit() and apply() in SharedPreferences?
    • commit() returns a boolean value of success or failure immediately by writing data synchronously.
    • apply() is asynchronous and it wont return any boolean response. If you have an apply() outstanding and you are performing commit(), then the commit() will be blocked until the apply() is not completed.
  • What is a Spannable?Learn from here
  • What is a SpannableString?
    • A SpannableString has immutable text, but its span information is mutable. Use a SpannableString when your text doesnt need to be changed but the styling does. Spans are ranges over the text that include styling information like color, heighliting, italics, links, etc
  • What are the best practices for using text in Android?Learn from here
  • How to implement Dark mode in any application?Learn from here
  • How to generate dynamic colors based in ?Learn from here
  • Explain about Density Independence PixelLearn from here
  • How to reduce battery usage in an android application?Learn from here
  • What is Doze? What about App Standby?Learn from here
  • What is overdraw?Learn from here
  • How do you support different types of resolutions?Learn from here
  • What are the different protection levels in permission?Learn from here
  • Design Uber App. – Learn from here
  • Design Facebook App.
  • Design Facebook Near-By Friends App.
  • Design WhatsApp.
  • Design SnapChat.
  • Design problems based on location based app.
  • How to build offline-first app? Explain the architecture.
  • Design LRU Cache.
  • Design File Downloader – Learn from here
  • Design an Loading Library – Learn from here
  • HTTP Request vs HTTP Long-Polling vs WebSockets – Learn from here
  • Explain OOP Concepts.
  • What is the difference between a constructor and a method?
    • The name of the constructor is same as that of the class name, whereas the name of the method can be anything.
    • There is no return type of a constructor.
    • When you make an object of a class, then the constructor of that class will be called automatically. But for methods, we need to call it explicitely.
    • Constructors cant be inherited but you can call the constructor of the parent class by calling super().
    • Constructor and a method they both run a block of code but the difference is in calling them.
    • We can call method directly using their name.
    • Constructor Syntax –
      public class SomeClassName{ SomeClassName(parameter_list ){ ... } ... }
    • Note: In the above syntax, the name of the constructor is the same as that of class and it has no return type.
    • Method Syntax
      public class SomeClassName{ public void someMethodName(parameter_list ){ ... } // call method someMethodName(parameter_list) }
  • Differences between abstract classes and interfaces?
    • An abstract class, is a class that contains both concrete and abstract methods (methods without implementations). An abstract method must be implemented by the abstract class sub-classes. Abstract classes cannot be instantiated and need to be extended to be used.
    • An interface is like a blueprint/contract of a class (or it may be thought of as a class with methods, but without their implementation). It contains empty methods that represent, what all of its subclasses should have in common. The subclasses provide the implementation for each of these methods. Interfaces are implemented.
  • What is the difference between iterator and enumeration in java?
    • In Enumeration we dont have remove() method and we can only read and traverse through a collection.
    • Iterators can be applied to any collection. In Iterator, we can read and remove items from a collection.
  • Do you agree we use composition over inheritance? Learn from here
  • Difference between method overloading and overriding.
    • Overloading happens at compile-time while Overriding happens at runtime: The binding of overloaded method call to its definition happens at compile-time however binding of overridden method call to its definition happens at runtime. More info on static vs. dynamic binding: StackOverflow.
    • Static methods can be overloaded which means a class can have more than one static method of same name. Static methods cannot be overridden, even if you declare a same static method in child class it has nothing to do with the same method of parent class as overridden static methods are chosen by the reference class and not by the class of the object. So, for example:
      public class Animal { public static void testClassMethod() { System.out.println("The static method in Animal"); } public void testInstanceMethod() { System.out.println("The instance method in Animal"); } } public class Cat extends Animal { public static void testClassMethod() { System.out.println("The static method in Cat"); } public void testInstanceMethod() { System.out.println("The instance method in Cat"); } public static void main(String[] args) { Cat myCat = new Cat(); myCat.testClassMethod(); Animal myAnimal = myCat; myAnimal.testClassMethod(); myAnimal.testInstanceMethod(); } }

      Will output:

      The static method in Cat // testClassMethod() is called from "Cat" reference The static method in Animal // testClassMethod() is called from "Animal" reference, // ignoring actual object inside it (Cat) The instance method in Cat // testInstanceMethod() is called from "Animal" reference, // but from "Cat" object underneath

      The most basic difference is that overloading is being done in the same class while for overriding base and child classes are required. Overriding is all about giving a specific implementation to the inherited method of parent class. Static binding is being used for overloaded methods and dynamic binding is being used for overridden/overriding methods. Performance: Overloading gives better performance compared to overriding. The reason is that the binding of overridden methods is being done at runtime. Private and final methods can be overloaded but they cannot be overridden. It means a class can have more than one private/final methods of same name but a child class cannot override the private/final methods of their base class. Return type of method does not matter in case of method overloading, it can be same or different. However in case of method overriding the overriding method can have more specific return type (meaning if, for example, base method returns an instance of Number class, all overriding methods can return any class that is extended from Number, but not a class that is higher in the hierarchy, like, for example, Object is in this particular case). Argument list should be different while doing method overloading. Argument list should be same in method Overriding. It is also a good practice to annotate overridden methods with @Override to make the compiler be able to notify you if child is, indeed, overriding parents class method during compile-time.

  • What are the access modifiers you know? What does each one do?
    • There are four access modifiers in Java language (from strictest to the most lenient):
      1. private variables, methods, constructors or inner classes are only visible to its containing class and its methods. This modifier is most commonly used, for example, to allow variable access only through getters and setters or to hide underlying implementation of classes that should not be used by user and therefore maintain encapsulation. Singleton constructor is also marked private to avoid unwanted instantiation from outside.
      2. Default (no keyword is used) this modifier can be applied to classes, variables, constructors and methods and allows access from classes and methods inside the same package.
      3. protected can be used on variables, methods and constructors therefore allowing access only to subclasses and classes that are inside the same package as protected members class.
      4. public modifier is widely-used on classes, variables, constructors and methods to grant access from any class and method anywhere. It should not be used everywhere as it implies that data marked with public is not sensitive and can not be used to harm the program.
  • Can an Interface implement another Interface?
    • Yes, an interface can implement another interface (and more than one), but it needs to use extends, rather than implements keyword. And while you can not remove methods from parent interface, you can add new ones freely to your sub-interface.
  • What is Polymorphism? What about Inheritance?
    • Polymorphism in Java has two types: Compile time polymorphism (static binding) and Runtime polymorphism (dynamic binding). Method overloading is an example of static polymorphism, while method overriding is an example of dynamic polymorphism. An important example of polymorphism is how a parent class refers to a child class object. In fact, any object that satisfies more than one IS-A relationship is polymorphic in nature. For instance, let’s consider a class Animal and let Cat be a subclass of Animal. So, any cat IS animal. Here, Cat satisfies the IS-A relationship for its own type as well as its super class Animal.
    • Inheritance can be defined as the process where one class acquires the properties (methods and fields) of another. With the use of inheritance the information is made manageable in a hierarchical order. The class which inherits the properties of other is known as subclass (derived class, child class) and the class whose properties are inherited is known as superclass (base class, parent class). Inheritance uses the keyword extends to inherit the properties of a class. Following is the syntax of extends keyword.
      class Super { ..... ..... } class Sub extends Super { ..... ..... }
  • Multiple inheritance in Classes and Interfaces in java Learn from here
  • What are the design patterns? Learn from here
  • Arrays Vs ArrayListsLearn from here and here
  • HashSet Vs TreeSetLearn from here
  • HashMap Vs SetLearn from here
  • Stack Vs QueueLearn from here
  • Explain Generics in Java?
    • Generics were included in Java language to provide stronger type checks, by allowing the programmer to define, which classes can be used with other classes

      In a nutshell, generics enable types (classes and interfaces) to be parameters when defining classes, interfaces and methods. Much like the more familiar formal parameters used in method declarations, type parameters provide a way for you to re-use the same code with different inputs. The difference is that the inputs to formal parameters are values, while the inputs to type parameters are types. (Official Java Documentation)

    • This means that, for example, you can define:
      List<Integer> list = new ArrayList<>();

      And let the compiler take care of noticing, if you put some object, of type other than Integer into this list and warn you.

    • It should be noted that standard class hierarchy does not apply to generic types. It means that Integer in List is not inherited from – it is actually inherited directly from . You can still put some constraints on what classes can be passed as a parameter into a generic by using wildcards like , or .
    • While generics are very useful, late inclusion into Java language has put some restraints on their implementation – backward compatibility required them to remain just “syntactic sugar” – they are erased (type erasure) during compile-time and replaced with object class.
  • What is Java PriorityQueue? – In Priority Queue, each element is having some priority and all the elements are present in a queue. The operations are performed based on the priority.
  • How is String class implemented? Why was it made immutable?
    • There is no primitive variant of String class in Java language – all strings are just wrappers around underlying array of characters, which is declared final. This means that, once a String object is instantiated, it cannot be changed through normal tools of the language (Reflection still can mess things up horribly, because in Java no object is truly immutable). This is why String variables in classes are the first candidates to be used, when you want to override hashCode() and equals() of your class – you can be sure, that all their required contracts will be satisfied.

      Note: The String class is immutable, so that once it is created a String object cannot be changed. The String class has a number of methods, some of which will be discussed below, that appear to modify strings. Since strings are immutable, what these methods really do is create and return a new string that contains the result of the operation. (Official Java Documentation)

      This class is also unique in a sense, that, when you create an instance like this:

      String helloWorld = "Hello, World!";

      "Hello, World!" is called a literal and compiler creates a String object with its value. So

      String capital = "Hello, World!".toUpperCase();

      is a valid statement, that, firstly, will create an object with literal value “Hello, World!” and then will create and return another object with value “HELLO, WORLD!”

    • String was made immutable to prevent malicious manipulation of data, when, for example, user login or other sensitive data is being send to a server.
  • What does it means to say that a String is immutable?
    • It means that once created, String objects char[] (its containing value) is declared final and, therefore, it can not be changed during runtime.
  • What is String.intern()? When and why should it be used?
    • String.intern() is used to mange memory in Java code. It is used when we have duplicates value in different strings. When you call the String.intern(), then if in the String pool that string is present then the equals() method will return true and it will return that string only.
  • Can you list 8 primitive types in java?
    • byte
    • short
    • int
    • long
    • float
    • double
    • char
    • String
    • boolean
  • What is the difference between an Integer and int?
    • int is a primitive data type (with boolean, byte, char, short, long, float and double), while Integer (with Boolean, Byte, Character, Short,Long, Float and Double) is a wrapper class that encapsulates primitive data type, while providing useful methods to perform different tasks with it.
  • What is Autoboxing and Unboxing?
    • Autoboxing and Unboxing is the process of automatic wrapping (putting in a box) and unwrapping (getting the value out) of primitive data types, that have “wrapper” classes. So int and Integer can (almost always) be used interchangeably in Java language, meaning a method void giveMeInt(int i) { ... } can take int as well as Integer as a parameter.
  • Typecast in Java
    • In Java, you can use casts to polymorph one class into another, compatible one. For example:
       long i = 10l; int j = (int) i; long k = j;

      Here we see, that, while narrowing (long i -> int j) requires an explicit cast to make sure the programmer realizes, that there may be some data or precision loss, widening (int j -> long k) does not require an explicit cast, because there can be no data loss (long can take larger numbers than int allows).

  • Do objects get passed by reference or value in Java? Elaborate on that.
    • In Java all primitives and objects are passed by value, meaning that their copy will be manipulated in the receiving method. But there is a caveat – when you pass an object reference into a method, a copy of this reference is made, so it still points to the same object. This means, that any changes that you make to the insides of this object are retained, when the method exits.
      public class Pointer { int innerField; public Pointer(int a) { this.innerField = a; } }
      public class ValueAndReference { public static void main(String[] args) { Pointer a = new Pointer(0); int b = 1; print("Before:"); print("b = " + b); print("a.innerField = " + a.innerField); exampleMethod(a, b); print("After:"); print("b = " + b); print("a.innerField = " + a.innerField); } static void exampleMethod(Pointer a, int b) { a.innerField = 2; b = 10; } static void print(String text) { System.out.println(text); } }

      Will output:

       Before: b = 1 a.innerField = 0 After: b = 1 // a new local int variable was created and operated on, so "b" didnt change a.innerField = 2 // Pointer a got its innerField variable changed // from 0 to 2, because method was operating on // the same reference to an instance
  • What is the difference between instantiation and initialization of an object?Learn from here
  • What the difference between local, instance and class variables?
    • Local variables exist only in methods that created them, they are stored separately in their respected Thread Stack (for more information, see question about Java Memory Model) and cannot have their reference passed outside of the method scope. That also means that they cannot be assigned any access modifier or made static – because they only exist during enclosing methods execution and those modifiers just do not make sense, since no other outside method can get them anyway.
    • Instance variables are the ones, that are declared in classes and their value can be different from one instance of the class to another, but they always require that class instance to exist.
    • Class variables are those, that are marked with static keyword in their class body. They can only have one value across all instances of that class (changing it in one place will change it in their class and, therefore, in all instances) and can even be retrieved without that class instance (if their access modifier allows it).
  • What is garbage collector? How does it work?
    • All objects are allocated on the heap area managed by the JVM. As long as an object is being referenced, the JVM considers it alive. Once an object is no longer referenced and therefore is not reachable by the application code, the garbage collector removes it and reclaims the unused memory.
  • What is Java Memory Model? What contracts does it guarantee? How are its Heap and Stack organized?Learn from here
  • What is memory leak and how does Java handle it?Learn from here
  • What are strong, soft, weak and phantom references in Java?Learn from here
  • What does the keyword synchronized mean? Learn from here
  • What is a ThreadPoolExecutor? Learn from here
  • What is volatile modifier? Learn from here
  • The classes in the atomic package expose a common set of methods: get, set,, lazyset, compareAndSet, and weakCompareAndSet. Please describe them.
  • How does the try{}, catch{}, finally works?Learn from here
  • What is the difference between a Checked Exception and an Un-Checked Exception?Learn from here
  • Complexity AnalysisLearn from here
    • What is Input, Output, Correctness, Efficiency of Algorithms?
    • What is Input Size and Running Time of Algorithms?
    • Explain the Worst, Best, and Average case analysis of Algorithms.
    • What is Big-O Notation with respect to Time and Space Complexity?
  • Iteration and Two Pointer ApproachLearn from here
    • Explain Initialization, Maintenance, and Termination used in iteration.
    • Explain the use-case of Two Pointer approach
  • Recursion and Divide & Conquer ApproachLearn from here
    • Explain Recursion with the help of an example and also draw the recursion call stack for the same.
    • How will you analyse the recursive solution of some problem?
    • Is there any difference between Recursion and Iteration?
    • Explain the Divide and Conquer technique with the help of a real-world example.
  • Arrays and Linked ListLearn from here
    • What do you mean by Linear Data Structures?
    • Explain the basic operations that can be performed on Arrays? Also, tell about Amortized analysis of array.
    • What is a Linked List? Explain with an example by performing some operations on Linked List.
    • What are the types of Linked List?
    • Can you tell the difference between an Array and a Linked List?
  • Stack and QueueLearn from here
    • What is a Stack? Explain various operations that can be performed on a Stack.
    • Can you implement Stack using an Array or using a Linked List? How?
    • What is a Queue? Explain various operations that can be performed on a Queue.
    • Can you implement Queue using an Array or using a Linked List? How?
    • Is there any difference between a Stack and a Queue?
  • Sorting AlgorithmsWikipedia
    • Using the most efficient sorting algorithm (and correct data structures that implement it) is vital for any program, because data manipulation can be one of the most significant bottlenecks in case of performance and the main purpose of spending time, determining the best algorithm for the job, is to drastically improve said performance. The efficiency of an algorithm is measured in its “Big O” (StackOverflow) score. Really good algorithms perform important actions in O(n log n) or even O(log n) time and some of them can even perform certain actions in O(1) time (HashTable insertion, for example). But there is always a trade-off – if some algorithm is really good at adding a new element to a data structure, it is, most certainly, much worse at data access than some other algorithm. If you are proficient with math, you may notice that “Big O” notation has many similarities with “limits”, and you would be right – it measures best, worst and average performances of an algorithm in question, by looking at its function limit. It should be noted that, when we are speaking about O(1) – constant time – we are not saying that this algorithm performs an action in one operation, rather that it can perform this action with the same number of operations (roughly), regrardless of the amount of elements it has to take into account. Thankfully, a lot of “Big O” scores have been already calculated, so you dont have to guess, which algorithm or data structure will perform better in your project. “Big O” cheat sheet
    • Bubble sort Wikipedia
      • Bubble sort is one of the simplest sorting algorithms. It just compares neighbouring elements and if the one that precedes the other is smaller – it changes their places. So over one iteration over the data list, it is guaranteed that at least one element will be in its correct place (the biggest/smallest one – depending on the direction of sorting). This is not a very efficient algorithm, as highly unordered arrays will require a lot of reordering (upto O(n^2)), but one of the advantages of this algorithm is its space complexity – only two elements are compared at once and there is no need to allocate more memory, than those two will occupy.
        Time Complexity Space Complexity
        Best Average Worst Worst
        Ω(n) Θ(n^2) O(n^2) O(1)
    • Selection sort Wikipedia
      • Firstly, selection sort assumes that the first element of the array to be sorted is the smallest, but to confirm this, it iterates over all other elements to check, and if it finds one, it gets defined as the smallest one. When the data ends, the element, that is currently found to be the smallest, is put in the beginning of the array. This sorting algorithm is quite straightforward, but still not that efficient on larger data sets, because to assign just one element to its place, it needs to go over all data.
        Time Complexity Space Complexity
        Best Average Worst Worst
        Ω(n^2) Θ(n^2) O(n^2) O(1)
    • Insertion sort Wikipedia
      • Insertion sort is another example of an algorithm, that is not that difficult to implement, but is also not that efficient. To do its job, it “grows” sorted portion of data, by “inserting” new encountered elements into already (innerly) sorted part of the array, which consists of previously encountered elements. This means that in best case (data is already sorted) it can confirm that its job is done in Ω(n) operations, while, if all encountered elements are not in their required order as many as O(n^2) operations may be needed.
        Time Complexity Space Complexity
        Best Average Worst Worst
        Ω(n) Θ(n^2) O(n^2) O(1)
    • Merge sort Wikipedia
      • This is a “divide and conquer” algorithm, meaning it recursively “divides” given array in to smaller parts (up to 1 element) and then sorts those parts, combining them with each other. This approach allows merge sort to achieve very high speed, while doubling required space, of course, but today memory space is more available than it was a couple of years ago, so this trade-off is considered acceptable.
        Time Complexity Space Complexity
        Best Average Worst Worst
        Ω(n log(n)) Θ(n log(n)) O(n log(n)) O(n)
    • Quicksort Wikipedia
      • Quicksort is considered, well, quite quick. When implemented correctly, it can be a significant number of times faster than its main competitors. This algorithm is also of “divide and conquer” family and its first step is to choose a “pivot” element (choosing it randomly, statistically, minimizes the chance to get the worst performance), then by comparing elements to this pivot, moving it closer and closer to its final place. During this process, the elements that are bigger are moved to the right side of it and smaller elements to the left. After this is done, quicksort repeats this process for subarrays on each side of placed pivot (does first step recursively), until the array is sorted.
        Time Complexity Space Complexity
        Best Average Worst Worst
        Ω(n log(n)) Θ(n log(n)) O(n^2) O(n)
    • There are, of course, more sorting algorithms and their modifications. We strongly recommend all readers to familiarize themselves with a couple more, because knowing algorithms is very important quality of a candidate, applying for a job and it shows understanding of what is happening “under the hood”.
  • Binary TreeLearn from here
    • What are non-linear data structures? Give example.
    • What is a Tree Data Structure? Explain the properties of tree with an example.
    • How is Binary Tree different from a normal Tree?
    • What is inorder, pre-order, post-order, and level-order traversal of a tree? Explain with an example.
    • Can you find the inorder, pre-order, and post-order of a tree using Stack? How?
    • Explain how searching, insertion, and deletion operations are performed on a Tree?
  • Binary Search TreeLearn from here
    • What is a Binary Search Tree? Explain its properties also.
    • Explain how searching, insertion, and deletion operations are performed on a Binary Search Tree?
    • How is Binary Search Tree different from Binary Tree?
  • Heap and Priority QueueLearn from here
    • What is a Heap data structure and when it is used?
    • Explain the operations that can be performed on a Heap.
    • What is the difference between a min-heap and a max-heap? How to implement these two?
    • What do you mean by Priority Queue? How to implement Priority Queue?
    • What are the real-life applications of Priority Queue?
  • Hash TableLearn from here
    • What do you mean by Direct Address Table?
    • Can you perform search, insert, and delete in O(1)? How?
    • Explain Hash Table and its properties.
    • How to remove collision in Hash Table by Chaining and Open Addressing?
    • What are the real-life applications of Hash Table?
  • Dynamic ProgrammingLearn from here
    • What is Dynamic Programming and how to find if a problem can be solved using DP or not?
    • What are two approaches of solving a Dynamic Programming problem?
    • Explain Optimization and Combinatorial problems?
  • Greedy AlgorithmsLearn from here
    • What do you mean by Greedy algorithms? How to find if a problem can be solved by Greedy approach or not?
    • Is there any difference between Dynamic Programming and Greedy Algorithms?
  • BacktrackingLearn from here
    • What is Backtracking?
    • How to find if a problem can be solved with Backtracking or not?
    • What is Exhaustive Searching?
  • GraphLearn from here
    • What is Graph and how to represent a Graph?
    • Explain Depth First Search and Breadth First Search.
    • How to represent a Graph?
    • What are the real-life applications of Graph?
    • What do you mean by Topological Sorting?
    • Explain Dijkstra algorithm with an example.
    • What is a Minimum Spanning Tree?
  • When your application starts accepting data input from end users you need to consider validating that input. To make sure it conforms to your overall requirements. In how many ways can you express validation?

    One way is to simply add your ViewModel as a nested element in the setter for the DataContext property as shown in the following code.

    The Model, View, ViewModel (MVVM pattern) is all about guiding you in how to organize and structure your code to write maintainable, testable and extensible applications. What are the logical layers of MVVM?

    Invoker is a piece of code which can execute some imperative logic. Typically, it is a UI element that the user interacts with in the context of a UI framework. But it could just be another chunk of logic code somewhere else in the application.

    Data binding is the key feature that differentiates MVVM from other UI separation patterns like MVC and MVP. In how many ways can you bind data?

    FAQ

    What are the elements of MVVM?

    Rationale. MVVM was designed to remove virtually all GUI code (“code-behind”) from the view layer, by using data binding functions in WPF (Windows Presentation Foundation) to better facilitate the separation of view layer development from the rest of the pattern.

    Is MVVM an architecture?

    Q3. What are the elements of MVVM? Ans: Model: as in the classic MVC pattern, the model refers to either (a) a domain model which represents the real state content (an object-oriented approach), or (b) the data access layer that represents that content (a data-centric approach).

    Related Posts

    Leave a Reply

    Your email address will not be published. Required fields are marked *