Interview Questions

1) What is Android?

Android is a mobile operating system which is found on a variety of modern devices, the most popular being smartphones. It is a Linux kernel-based system that’s been equipped with rich components that allows developers to create and run apps that can perform both basic and advanced functions.

2) What Is the Google Android SDK?

Android software development is the process by which new applications are created for the Android operating system.A software development kit that enables developers to create applications for the Android platform. The Android SDK includes sample projects with source code, development tools, an emulator, and required libraries to build Android applications.

3) What is the Android Architecture?

Android is architected in the form of a software stack comprising applications, an operating system, run-time environment, middleware, services and libraries.

Following are the different layers in the Android stack:

  • Linux Kernel Layer
  • Native Layer
  • Application Framework Layer
  • Applications layer

 

source: https://developer.android.com/guide/platform/index.html

5) What is AAPT?

AAPT is short for Android Asset Packaging Tool. This tool provides developers with the ability to deal with zip-compatible archives, which includes creating, extracting as well as viewing its contents.

6)What is ADB?

Android Debug Bridge (adb) is a versatile command-line tool that lets you communicate with a device (an emulator or a connected Android device). It’s a “bridge” for developers to work out bugs in their Android applications.

7)What is Dalvik/ART?

ART (Android RunTime) is the next version of Dalvik.Dalvik is the runtime, bytecode, and VM used by the Android system for running Android applications.

ART has two main features compared to Dalvik:

  • Ahead-of-Time (AOT) compilation, which improves speed (particularly startup time) and reduces memory footprint (no JIT)
  • Improved Garbage Collection (GC)

8)What is an Android manifest file?

The manifest presents essential information about the application to the Android system, information the system must have before it can run any of the application’s code.  It is a key file that works as a bridge between the android developer and the android platform.

It performs some other tasks also:

  • It is responsible to protect the application to access any protected parts by providing the permissions.
  • It also declares the android api that the application is going to use.
  • It lists the instrumentation classes. The instrumentation classes provides profiling and other informations. These informations are removed just before the application is published etc.

9)What is an Intent?

An intent is an abstract description of an operation to be performed. It can be used with startActivity to launch an ActivitybroadcastIntent to send it to any interested BroadcastReceiver components, and startService(Intent) or bindService(Intent, ServiceConnection, int) to communicate with a background Service.

Android Intent is the message that is passed between components such as activities, content providers, broadcast receivers, services etc.

Types of Android Intents

There are two types of intents in android: implicit and explicit.

  • Explicit intents specify the component to start by name (the fully-qualified class name). You’ll typically use an explicit intent 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 can start a new activity in response to a user action or start a service to download a file in the background
Intent i = new Intent(this, ActivityTwo.class);
startActivity(i);
  • Implicit intents 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.
       Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www......"));
       startActivity(i);

 

10)What is a Service?

Service is an application component that can perform long-running operations in the background, and it does not provide a user interface.

service is a component that runs in the background to perform long-running operations without needing to interact with the user and it works even if application is destroyed.

11)What is an IntentService?

IntentService is a base class for Services that handle asynchronous requests (expressed as Intents) on demand.Service is a base class for IntentService Services that handle asynchronous requests (expressed as Intents) on demand. Clients send requests through startService(Intent)calls; the service is started as needed, handles each Intent in turn using a worker thread, and stops itself when it runs out of work.

12)What is an AsyncTask?

AsyncTask is an abstract Android class which helps the Android applications to handle the Main UI thread in efficient way. AsyncTask  class allows us to perform long lasting tasks/background operations and  show the result on the UI thread without affecting the main thread.

13)What is a ContentProvider?

content provider manages access to a central repository of data.Content providers can help an application manage access to data stored by itself, stored by other apps, and provide a way to share data with other apps. They encapsulate the data, and provide mechanisms for defining data security.One of your classes implements a subclass ContentProvider, which is the interface between your provider and other applications.

14)What is the lifecycle of an Activity?

An activity is a single focused thing that the user can do.An activity represents a single screen with a user interface just like window or frame of Java.Android activity is the subclass of ContextThemeWrapper class.

Enter image description here

onCreate():

Called when the activity is first created. This is where you should do all of your normal static set up: create views, bind data to lists, etc. This method also provides you with a Bundle containing the activity’s previously frozen state, if there was one. Always followed by onStart().

onRestart():

Called after your activity has been stopped, prior to it being started again. Always followed by onStart()

onStart():

Called when the activity is becoming visible to the user. Followed by onResume() if the activity comes to the foreground, or onStop() if it becomes hidden.

onResume():

Called when the activity will start interacting with the user. At this point your activity is at the top of the activity stack, with user input going to it. Always followed by onPause().

onPause ():

Called as part of the activity lifecycle when an activity is going into the background, but has not (yet) been killed. The counterpart to onResume(). When activity B is launched in front of activity A, this callback will be invoked on A. B will not be created until A’s onPause() returns, so be sure to not do anything lengthy here.

onStop():

Called when you are no longer visible to the user. You will next receive either onRestart(), onDestroy(), or nothing, depending on later user activity.

Note that this method may never be called, in low memory situations where the system does not have enough memory to keep your activity’s process running after its onPause() method is called.

onDestroy():

The final call you receive before your activity is destroyed. This can happen either because the activity is finishing (someone called finish() on it, or because the system is temporarily destroying this instance of the activity to save space. You can distinguish between these two scenarios with the isFinishing() method.

15)What is an Adapter in Android?

An Adapter object acts as a bridge between an AdapterView and the underlying data for that view. The Adapter provides access to the data items. The Adapter is also responsible for making a View for each item in the data set.The Adapter is actually an interface.

16)Why cannot you run standard Java bytecode on Android?

Android uses Dalvik Virtual Machine (DVM) which requires a special bytecode.  Java class files convert into Dalvik Executable files using an Android tool called “dx”.

The Dalvik Virtual Machine (DVM) is an android virtual machine optimized for mobile devices. It optimizes the virtual machine for memorybattery life and performance.

Multiple class files are converted into one dex file.

17. What is the difference between a regular .png and a nine-patch image?
The nine patch images are extension with .9.png. Nine-patch image allows resizing that can be used as background or other image size requirements for the target device. The Nine-patch refers to the way you can resize the image: 4 corners that are unscaled, 4 edges that are scaled in 1 axis, and the middle one that can be scaled into both axes.
18. What are the different storage methods in Android?
 Shared Preferences.
Store private primitive data in key-value pairs.
– Internal Storage.
Store private data on the device memory.
– External Storage.
Store public data on the shared external storage.
– SQLite Databases.
Store structured data in a private database.
– Network Connection.
Store data on the web with your own network server.
19. What is an ANR notification in Android?
ANR is short for Application Not Responding. Android systems show this dialog if the application is performing too much of task on the main thread and has been unresponsive from a long time.
20.Which dialog boxes can you use in your Android application?
  • AlertDialog : An alert dialogue box supports 0 to 3 buttons and a list of selectable elements.
  • ProgressDialog : An extension to AlertDialog and you may add buttons to it. It shows a progress wheel or a progress bar.
  • DatePickerDialog : It is used for selecting a date by the user.
  • TimePickerDialog : It is used for selecting time by the user.

21.How can ANR be prevented?

One technique that prevents the Android system from concluding a code that has been responsive for a long period of time is to create a child thread. Within the child thread, most of the actual tasks of the codes can be placed, so that the main thread runs with minimal periods of unresponsive time.

22.What is a bundle?

Bundles are generally used for passing data between various Android activities. It depends on you what type of values you want to pass, but bundles can hold all types of values and pass them to the new activity.

You can use it like this:

Intent intent = new...
Intent(getApplicationContext(), SecondActivity.class);
intent.putExtra("myKey", AnyValue);  
startActivity(intent);

You can get the passed values by doing:

Bundle extras = intent.getExtras(); 
String tmp = extras.getString("myKey");

23.What is Service?

A service is a component that runs in the background. It is used to play music, handle network transaction etc.

Service are part of the application and run on a different thread in the background and supports some long-running operation, such as, handling location updates from the LocationManager as in the case of My Runs. Typically, services operate outside of the user interface.

 

24.Service Runs on which thread?

In Android, a Service is an application component that can perform long-running operations in the background on the UI thread. By background, it means that it doesn’t have a user interface. A Service runs on the main thread of the calling Component’s process by default (and hence can degrade responsiveness and cause ANRs), hence you should create a new Thread to perform long running operations. A Service can also be made to run in a completely different process.

25.What is Notification?

Allows apps or services associated with an app to inform the user of an event.The Notification.Builder provides an builder interface to create an Notification object. 

26.What is AAPT?

AAPT is an acronym for android asset packaging tool. It handles the packaging process.

27.What is Content Provider?

Content providers are used to share information between android applications.

A content provider component supplies data from one application to others on request. Such requests are handled by the methods of the ContentResolver class. A content provider can use different ways to store its data and the data can be stored in a database, in files, or even over a network.

28.What is Fragment?

Fragment is a part of Activity. By the help of fragments, we can display multiple screens on one activity.

 

29.What is NDK?

NDK stands for Native Development Kit. By using NDK, you can develop a part of app using native language such as C/C++ to boost the performance.

30.What is APK?

APK is a short form stands for Android Packaging Key. It is a compressed key with classes,UI’s, supportive assets and manifest. All files are compressed to a single file is called APK.

31.How to pass object using intent?

intent.putExtra(“MyClass”, obj);

// To retrieve object in second Activity

getIntent().getSerializableExtra(“MyClass”);

32.How to Bound Service / how to bind service with activity?

A bound service is the server in a client-server interface. A bound service allows components (such as activities) to bind to the service, send requests, receive responses such as data.

33.What is Picasso?

http://square.github.io/picasso/

A powerful image downloading and caching library for Android.

34.What is Retrofit?

http://square.github.io/retrofit/

A type-safe HTTP client for Android and java.

35.What is volley?

Volley is a library that makes networking for Android apps easier and most importantly, faster. It manages the processing and caching of network requests and it saves developers valuable time from writing the same network call/cache code again and again.

36.What is Broadcast Receiver?

Broadcast Receivers are used to receive events that are announced by other components. For example, activities or other Android components can register for a specific Broadcast Receivers. Receivers that registers will receive intents when other components issue sendBroadcast().

37.Call GUI by using service?

  • Use a bound service which enables the Activity to get a direct reference to the Service, thus allowing direct calls on it, rather than using Intents.
  • Use RxJava to execute asynchronous operations.
  • If the Service needs to continue background operations even when no Activity is running, also start the service from the Application class so that it does not get stopped when unbound.

38.Android application to be only run in portrait mode?

In the manifest, set this for all your activities:

<activity android:name=".YourActivity"
    android:configChanges="orientation"
    android:screenOrientation="portrait"/>

Let me explain:

  • With android:configChanges="orientation" you tell Android that you will be responsible of the changes of orientation.
  • android:screenOrientation="portrait" you set the default orientation mode.

39.What is Pending intent?

A Pending Intent is a token you give to some app to perform an action on your apps’ behalf irrespective of whether your application process is alive or not.

Intent intent = new Intent(context, MainActivity.class);
PendingIntent pendIntent = PendingIntent.getActivity(context, 0, intent, 0)

40.What is Serialization?

Serialization is a mechanism of converting the state of an object into a byte stream. Deserialization is the reverse process where the byte stream is used to recreate the actual Java object in memory. This mechanism is used to persist the object.

41.What is Content Resolver?

The ContentResolver decides which provider to use based on the authority part of the URI.Whenever you want to use another content provider you first have to access a ContentResolver object. This object is responsible for finding the correct content provider.

The Content Resolver includes the CRUD (create, read, update, delete) methods corresponding to the abstract methods (insert, query, update, delete) in the Content Provider class.

42.What is Content Values?

Content Values is a  name value pair,used to insert or update values into database tables.ContentValues object will be passed to SQLiteDataBase objects insert() and update() functions.

43.What is Cursor?

Cursor is a temporary buffer area which stores results from a SQLiteDataBase query.

44.What is fragment Manager?

FragmentManager which is used to create transactions for adding, removing or replacing fragments.

fragmentManager.beginTransaction();

With FrameLayout we can handle fragments as we need at runtime, but to do it we need a manager, in other words a component that can handle fragments. This is FragmentManager. This component can addreplace and remove fragments at runtime.

45.What is Fragment Transaction?

FragmentTransaction gives us methods to add, replace, or remove fragments in Android. It gives us an interface for interacting with fragments.

fragmentTransaction.replace(R.id.fragment_container, mFeedFragment);

The method replace(int containerViewId, Fragment fragment) replaces an existing Fragmentobject from the container containerViewId and adds the the Fragment fragment

fragmentTransaction.addToBackStack(null);

This method, addToBackOfStack(String name), adds this transaction to the back stack, this can be used so that Fragments are remembered and can be used again by the Activity

fragmentTransaction.commit();

The method commit() schedules this transaction, this is not instantaneous; It is scheduled on the main thread to be done when the thread is ready.

46.What is shared preferences?

Shared Preferences allows activities and applications to keep preferences, in the form of key-value pairs similar to a Map that will persist even when the user closes the application.

SharedPreferences is application specific, i.e. the data is lost on performing one of the following options:

  • on uninstalling the application
  • on clearing the application data (through Settings)

Editor editor = sharedpreferences.edit();
editor.putString(“key”, “value”);
editor.commit();

47.What is Tasks?

A task is a collection of activities that users interact.

Normally when user launch an application a new task will be created and the first activity instance is called root of the task.

When user launches an app from home icon, it navigates through different screens so different activities placed on the top of one another. This collection of activities is known as tasks.

48.What is Back Stack?

Activities are arranged with the order in which each activity is opened. This maintained stack called Back Stack. When you start a new activity using startActivity(), it “pushes” a new activity onto your task, and put the previous Activity in the back stack.

49.What is  launch modes for activity?

There are four launch modes for activity. They are:

1. standard

This is the default launch mode of an activity .It creates a new instance of an activity in the task from which it was started. Multiple instances of the activity can be created and multiple instances can be added to the same or different tasks.

2. singleTop

In this launch mode if an instance of activity already exists at the top of the current task, a new instance will not be created and Android system will route the intent information through onNewIntent(). If an instance is not present on top of task then new instance will be created.

3. singleTask

In this launch mode a new task will always be created and a new instance will be pushed to the task as the root one. If an instance of activity exists on the separate task, a new instance will not be created and Android system routes the intent information through onNewIntent() method. At a time only one instance of activity will exist.

4. singleInstance

This is very special launch mode and only used in the applications that has only one activity. It is similar to singleTask except that no other activities will be created in the same task. Any other activity started from here will create in a new task.

50.What are  Views?

Views are a class in the Android UI framework. They occupy a rectangular area on the screen and are responsible for drawing and handling events.An activity determines what views to create (and where to put them), by reading an XML layout file.

The android.widget package contains a list of most of the UI view classes available to you.

51.Difference between padding and layout_margin?

The difference is that padding determines space within the boundaries of the view, and layout_margin determines the space outside the boundaries of the view.

52.How do the XML Layouts relate to the Java Activites?

After you create your XML Layout you need to associate it with your activity. This is done in the onCreate method of the Activity using the method setContentView. You pass a reference to the layout file as R.layout.name_of_layout.

53.What is the R Class?

When your application is compiled the R class is generated. It creates constants that allow you to dynamically identify the various contents of the res folder, including layouts.

54.What is the methodsetContentView do?

It inflates the layout.

55.What is FrameLayout?

A FrameLayout is a layout that generally contains one view or overlapping views.  Generally, FrameLayout should be used to hold a single child view, because it can be difficult to organize child views in a way that’s scalable to different screen sizes without the children overlapping each other.

56.What is Asynctask?

AsyncTask allow you to run a task on background thread,while publishing result to UI Thread.Async task is a Generic class .Means it takes parameterized types in a constructor.Async calls a onPreExecute() on UI thread while at execution time .To execute background task call doInBackgound() method.To update the UI calls publishProgress() and at the end call onPostExecute .

 

57.What is JSON?

JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write,more compact,easier to write,allow for declaration of arrays. It is Primary method for data exchange on the web.

58.What is viewHolder?

ViewHolder object stores each of the component views inside the tag field of the Layout, so you can immediately access them without the need to look them up repeatedly. The ViewHolder design pattern enables you to access each list item view without the need for the look up, saving valuable processor cycles.

59.How to pass a data from one fragment to another?

 SecondFragment ft fr=new SecondFragment ();
 FragmentManager fm=getFragmentManager();
 android.app.FragmentTransaction ft=fm.beginTransaction();
 Bundle args = new Bundle();
 args.putString("CID", "your value");
 fr.setArguments(args);
 ft.replace(R.id.content_frame, fr);
 ft.commit(); 

To receive the data do the following,

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    String strtext = getArguments().getString("CID");    
    return inflater.inflate(R.layout.fragment, container, false);
}

60.

1+

1 comments on “Interview Questions”

  1. Reply

    I have interest in this, thanks.

    0

Leave a Reply

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