Common Tasks and How To Do Them in Android

  • Build and install your package. The Android SDK has some nice tools for generating projects and debugging code.
  • Adding an External Library (.jar) using Eclipse

    You can use a third party JAR in your application by adding it to your Eclipse project as follows:

    1. In the Package Explorer panel, right-click on your project and select Properties.
    2. Select Java Build Path, then the tab Libraries.
    3. Press the Add External JARs... button and select the JAR file.

    Alternatively, if you want to include third party JARs with your package, create a new directory for them within your project and select Add Library... instead.

    It is not necessary to put external JARs in the assets folder.

    Implementing Activity Callbacks

    Android calls a number of callbacks to let you draw your screen, store data before pausing, and refresh data after closing. You must implement at least some of these methods. See Building an Android Sample Application for more information on using

        AndroidManifest.xml (required) Advertises the screens that this application provides, where they can be launched (from the main program menu or elsewhere), any content providers it implements and what kind of data they handle, where the implementation classes are, and other application-wide information. Syntax details for this file are described in Layout Resources for the syntax of these files.

    (optional) XML files describing additional resources such as strings, colors, and styles. The naming, quantity, and number of these files are not enforced--any XML file is compiled, but these are the standard names given to these files. However, the syntax of these files is prescribed by Android, and described in Resources.

            xml/ (optional) XML files that can be read at run time on the device.
            raw/ (optional) Any files to be copied directly to the device.

    Print Messages to a Log File

    To write log messages from your application:

    1. Import android.util.Log.
    2. Use Log.v(), Log.d(), Log.i(), Log.w(), or Log.e() to log messages. (See the Log class.)
      E.g., Log.e(this.toString(), "error: " + err.toString())
    3. Launch DDMS from a terminal by executing ddms in your Android SDK /tools path.
    4. Run your application in the Android emulator.
    5. From the DDMS application, select the emulator (e.g., "emulator-5554") and click Device > Run logcat... to view all the log data.

    Note: If you are running Eclipse and encounter a warning about the VM debug port when opening DDMS, you can ignore it if you're only interested in logs. However, if you want to further inspect and control your processes from DDMS, then you should close Eclipse before launching DDMS so that it may use the VM debugging port.