Android General FAQ

What is the Life Cycle of an Activity?

The activity lifecycle includes many states, beginning with the creation of the activity and ending in the destruction of the activity. When an activity changes state, the appropriate lifecycle event method is called, notifying the activity of the state change enabling it to execute code in order to handle the change.

The activity lifecycle methods include:

  • onCreate(): called when the activity is first created
  • onStart(): called when the activity is about to become visible
  • onPause(): called when the system is about to put the activity in the background
  • onResume(): called when the activity will start interacting with the user
  • onStop(): called when the activity is no longer visible
  • onRestart(): called after the activity has been stopped, and prior to it starting
  • onDestroy(): called right before the activity is about to be destroyed

What are all the methods used to write Log messages?

The class android.util.Log provides 5 methods for writing log messages.

These methods, listed in order of verbosity (most to least), are:

  • v(): Sends a VERBOSE message
  • d(): Sends a DEBUG message
  • i(): Sends an INFO message
  • w(): Sends a WARN message
  • e(): Sends an ERROR message

Verbose should never be compiled into an application except during development. Debug logs are compiled in but stripped at runtime. Error, warning and info logs are always kept.

Why is R.java convenient for working with resources?

R.java is convenient for working with resources because it allows you to access identifiers that are found outside the scope of the java source, like the XML files which define layouts, strings and other values.

What are the different resource types?

Resource Types:

  • Animation Resources: for defining pre-determined animations
  • Color State List Resources: for defining color resources
  • Drawable Resources: for defining various graphics
  • Layout Resource: for defining the layout of the UI
  • Menu Resource: for defining the contents of the menus
  • String Resources: for defining strings and string lists
  • Style Resource: for defining the look and format of the UI elements

What is the adb tool?

The Android Debug Bridge (adb) tool allows the development machine to communicate with an emulator (virtual device) or a connected physical device.

What is an intent and how can it be used to invoke an activity?

Intents are asynchronous messages which allow Android components to request functionality from other components of the Android system. Intents can be used to signal to the Android system that a certain event has occurred.

You can use an Intent to invoke another activity with the following code:

# Start ActivityTwo
Intent intent = new Intent(this, ActivityTwo.class);
startActivity(intent);

An explicit intent explicitly defines the component that should be called by the Android system by using the Java class as an identifier.

An implicit intent specifies the action that should be performed and optionally provides data for the action.

What are the items that an Android project is made of?

An Android project is made of:

  • Source code (/src): The source code defines Activities and other related classes, written in Java
  • Generated code (/gen): Generated code, including R.java, should not be modified and are used as helper classes.
  • Generated binaries (/bin): Includes the compiled .apk file
  • Resources (/res)
  • Assets (/assets)
  • AndroidManifest.xml

What is the function of the intent filter?

Intent filters are used to filter out intents that a component is willing to receive. One or more filters are possible, depending on the services and activities that are going to make sure of it.

What are the four essential states of an Activity?

The four essential states of an activity are:

  • Active: the activity is in the foreground
  • Paused: the activity is in the background and still visible
  • Stopped: the activity is not visible and therefore obscured by another activity
  • Destroyed: the process is killed

What does the AndroidManifest.xml file do?

The AndroidManifest.xml file is essential to every Android application. It is declared in the root directory and contains information about the application that the Android system must know before the code can be executed.

Leave a Reply

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