This sample demonstrates how an application can make use of shared code and resources stored in an Android library project.
In this case, the TicTacToeMain application project includes a reference to
the TicTacToeLib library project. When you build the TicTacToeMain application,
the build tools look for the library project and compile it's code and resources
as part of the main application's .apk
file. The main application
is designed with a launcher activity called MainActivity
, shown at
left, below. When the user presses a button in the View,
MainActivity
starts a second activity, GameActivity
,
which is declared in the library project.
MainActivity
, which is implemented locally in main project,
and GameActivity
, which is implemented in the library project.
Currently, an application must declare in its manifest any components or
resources that it is using from a library project.GameActivity
component declared in the TicTacToeLib
library project. The TicTacToeLib library project includes a single Activity,
GameActivity
, that handles most of the application lifecycle.
GameActivity
.If you want to build the TicTacToeMain application, you can obtain it by downloading the "Samples for SDK API 8" component (or higher version) into your SDK, using the Android SDK and AVD Manager. Note that the application project depends on code and resources found in the TicTacToeLib library project — in order to build TicTacToeMain, you need to add both projects to your development environment.
To build an application that uses a library project, you also need to update to the latest version of the SDK tools (r6 or higher) and Android platforms, as well as the latest version of ADT (0.9.7 or higher), if you are developing in Eclipse.
For information about how to set up Android library projects, refer to Developing in Eclipse with ADT or Developing in Other IDEs, depending on your environment.
You can find the source code for this sample in your SDK at:
<sdk>/platforms/android-<version>/samples/