Android Interview Questions
Android Interview Questions
Android Interview Questions
• What is Application?
o 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 Context?
o Android uses DVM (Dalvik Virtual Machine ) rather using JVM(Java Virtual
Machine).
o First step involves compiling the resources folder (/res) using the aapt
(android asset packaging tool) tool. These are compiled to a single class
file called R.java. This is a class that just contains constants.
o Second step involves the java source code being compiled to .class files by
javac, and then the class files are converted to Dalvik bytecode by the "dx"
tool, which is included in the sdk 'tools'. The output is classes.dex.
o The final step involves the android apkbuilder which takes all the input and
builds the apk (android packaging key) file.
• Describe activities
• Lifecycle of an Activity
o OnCreate(): This is when the view is first created. This is normally where we
create views, get data from bundles etc.
o 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.
o 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.
o OnPause(): Called as part of the activity lifecycle when an activity is going
into the background, but has not (yet) been killed.
o OnStop(): Called when you are no longer visible to the user.
o OnDestroy(): Called when the activity is finishing
o OnRestart(): Called after your activity has been stopped, prior to it being
started again
o The onCreate() method is called once during the Activity lifecycle, either
when the application starts, or when the Activity has been destroyed and
then recreated, for example during a configuration change.
o The onStart() method is called whenever the Activity becomes visible to
the user, typically after onCreate() or onRestart().
• How does the activity respond when the user rotates the screen?
• How to prevent the data from reloading and resetting when the screen is
rotated?
• Mention two ways to clear the back stack of Activities when a new Activity
is called using intent
o Start by making sure your Android application has the necessary read
access permissions. Then, get access to the ContentResolver object by
calling getContentResolver() on the Context object, and retrieving the data
by constructing a query using ContentResolver.query().
o The ContentResolver.query() method returns a Cursor, so you can retrieve
data from each column using Cursor methods.
• Describe services
o Service is the base class for Android services that can be extended to
create any service. A class that directly extends Service runs on the main
thread so it will block the UI (if there is one) and should therefore either be
used only for short tasks or should make use of other threads for longer
tasks.
o IntentService is a subclass of Service that handles 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
wor