upwork.com: 10 Android interview questions and answers
What are the 7 core building blocks of an Android application
1) Activity 2) View 3) Intent 4) Service 5) Content Provider 6) Fragment 7) Android Manifest
Briefly list the 5 components of the Android architecture.
1) Linux Kernel 2) Native Libraries 3) Android Runtime 4) Application Framework 5) Applications
Can you list and explain the four Java classes related to using sensors on the Android platform?
1) SensorManager 2) Sensor 3) SensorEvent 4) SensorEventListener
Service
A service is a background process that can either be local or remote. Local services may be accessed from within the application while remote services are intended to be used by other applications running on the same device.
Activity
An activity is a subclass of the "ContextThemeWrapper" class. Since almost all activities interact directly with the user, it is often helpful to think of an activity as the screen for a particular action, such as logging in or taking a picture.
Content Provider
Content providers share data between applications.
What is DDMS and what can it do?
DDMS is short for Dalvik Debug Monitor Server. It ships natively with Android and contains a number of useful debugging features including: location data spoofing, port-forwarding, network traffic tracking, incoming call/SMS spoofing, thread and heap information, screen capture, and the ability to simulate network state, speed, and latency.
Fragment
Fragments are best thought of as parts of an activity—you can display more than one fragment on the screen at the same time.
Native Libraries
Resting on top of the Linux Kernel are a set of open-source libraries, including the SQLite database, libc, and the WebKit browser engine.
What is SQLite? How does it differ from client-server database management systems?
SQLite is the open-source relational database of choice for Android applications. The SQLite engine is serverless, transactional, and self-contained. Instead of the typical client-server relationship of most database management systems, the SQLite engine is integrally linked with the application. The library can also be called dynamically, and makes use of simple function calls that reduce latency in database access.
Android Manifest
The AndroidManifest.xml file provides essential information about your app required for it to run on the Android operating system. All Android apps have this file in their root directory.
Android Runtime
The Dalvik Virtual Machine is in the same level as the Native Libraries and allows every Android app to run its own processes.
Linux Kernel
The base layer of an application that directly interfaces with the device hardware—this is the level that deals with hardware drivers like the camera, keypad, and display.
What are some measures you can take to avoid ANR?
The dreaded ANR (Application Not Responding) message appears to the user when an Android application remains unresponsive for a long period of time. ANR is typically caused when the app performs too much on the main thread. To avoid ANR, an app should perform lengthy database or networking operations in separate threads. For background task-intensive apps, you can alleviate pressure from the UI thread by using the IntentService. In general, it helps to always define time-outs for all your web service calls and to remain ever vigilant for infinite loops in complex calculations.
Write a quick script for launching a new activity within your application.
The goal of this question is to quickly test their knowledge of explicit intent in launching an activity. An explicit intent explicitly defines the activity the developer wishes to start. A possible solution has been produced below. Intent myIntent = new Intent(this, MyNewActivity.class); startActivity(myIntent);
Intent
The main purpose of intent is to invoke individual components. Common uses include starting the service, launching activities, displaying a list of contacts, dialing a phone number, or displaying a web page.
Application Framework
The next layer up provides higher-level services in the form of Java classes to applications on the device. The key services to know are the Activity Manager, Content Providers, Resource Manager, Notifications Manager, and the View System.
What are the seven lifecycle methods of Android activity and what is their purpose?
The seven lifecycle methods of Android activity are onCreate(), onStart(), onRestart(), onResume(), onPause(), onStop(), and onDestroy(). Their purpose is to help structure your code around how you want an activity to perform throughout its lifecycle on the device. For example, onCreate() is where you would perform your static setup, from creating views to binding data to lists. It is always immediately followed by onStart(), where the app will be made visible to the user. What you're looking for in their response is a solid grasp of the lifecycle of an Android app. The functions of these methods are pretty self-explanatory based on their names, especially when you see Android's lifecycle below.
Applications
The top layer is the Android App itself. This is the level where applications are actually installed, and the one developers are most familiar with.
View
The view is everything you can see on the screen of the app—think of the individual UI elements like buttons, labels, and text fields.
Sensor
This class creates an instance of a specific sensor, providing methods that allow you to determine its capabilities.
SensorEvent
This class provides information on a sensor event by creating a sensor event object.
Sensor Manager
This class provides methods regarding the registration of sensor event listeners, the management of data acquisition, and calibration. It also provides methods for accessing and listing sensors.
SensorEventListener
This interface provides two callback methods that can receive notifications of sensor events.
How would you check for the presence of a Compass sensor on the system using the hasSystemFeature() method?
While it may be tempting to call this method on SensorManager or Sensor, as they both come as part of the Android Sensor Framework, neither of those classes provide the hasSystemFeature() method. These classes are intended for direct access and acquisition of raw sensor data. When it comes to evaluating a system's capabilities, the PackageManager class can be used to retrieve information on application packages available on a given device. One possible solution to this problem is reproduced below. PackageManager myCompass = getPackageManger(); If (!myCompass.hasSystemFeature(PackageManager.FEATURE_SENSOR_COMPASS)) { // This device lacks a compass, disable the compass feature }
Why did you become an Android developer? What are 4 of the advantages of the Android platform?
You want a developer who really knows how to play to the strengths of your chosen platform. Some key advantages of Android are listed below for your convenience. -Open Source: No licenses, no distribution or development fees. -DVM (Dalvik Virtual Machine): DVM is a highly optimized virtual machine for mobile devices. -Platform Diversity: Since Android is open-source, it has been adopted by a wide range of manufacturers of mobile devices. -Experience with Java: Java is the language of choice for Android app development. Those who already have years of experience in Java will feel right at home developing for Android.