And three lucky winners stand a chance to win ecopy of their new book. Keep reading to find out how you can be one of the Lucky Winners.

Overview

Install Android Studio and configure the Android Software Development Kit

Create your first project and explore its structure

Improve your productivity while programming, by getting the best from the code editor

Design the user interface and learn how to handle user events

Integrate the Google Play Services into your app

Test your app using the emulator and learn how to manage the virtual devices

Run and debug your app

Monitor your app whilst it is running and improve its performance

Build your app for release

How to Enter?

All you need to do is write your e-mail and name below. It’s that simple. Winners will be contacted by email, so be sure to use your real email address when you comment!

In the second step, you can get extra entries if:

You head on over to the book page (Android Studio Application Development) and look through the product description of the book and drop a line via the comments after sending your email, to let us know what interests you the most about this book.

You tweet about this giveaway.

You follow me on twitter.

Winners from the U.S. and Europe can either choose a physical copy of the book or the eBook. Users from other locales are limited to the eBook only.

You need to enable javascript to enter this campaign !Powered by PromoSimple.

In this post, I will show in detail the second one: to create the resources programmatically instead of using the XML files and export it to a JAR file. The steps are the following:

Create a java project to add the code.

Import the Android SDK into the java project.

Create the resources programmatically.

Export the java project to a .JAR file excluding the source code.

Import the .JAR into the client project or add an intermediate Android Library Project.

Let’s show a short example, the same example used in the part II. Suppose we want to create a library to provide a log-in screen to authenticate users in our system. We want to keep the code that connects to our servers and authenticates the users in private. We also want to provide the user interface in order to maintain our own corporative design and now we will keep that user interface in private too.

1. Create the Java project

Create a Java project and create a package and a class in it. Let’s name the class “Authenticator”, a final class with one static method. This class has the code of our authentication system.

2. Import the Android Jar

Add the Android library to the project as you would do to add any external library .jar. You will find de android.jar file in the Android installation from your system, for example in a path like /androidSDK/platforms/android-18/android.jar.

3. Create the resources

We are creating the resources programmatically, that’s why we added the android.jar in the previous step. Create a new final class named as “LayoutCreator”. In this class we add the method that will contain the code to create the login layout. We can add different methods for different views. Additionally, we will have to create the R.java class to store the IDs of the layout components.

And finally we need to handle the button event. We get the user credentials from the layout and start the authentication process. Since the login is a costly process, we execute it in a new thread. To simplify the example, I used a Runnable object, a better way would have been the use of an AsyncTask.

Export the project to a .JAR file excluding the source code. If you are using eclipse, then in the export dialog, just check the “Export generated class files and resources” option, but don’t check the option “Export Java source files and resources“.

4. Create an Android Library Project

Create a new Android project and check it as a library project.

Import our library .JAR from the previous step.

Open the main activity and in the onCreate method we need to change the view that is loaded from this activity. Change the call to the setContentView method to this:

setContentView(LayoutCreator.createLoginLayout(this));

5. Create the client Android project

Create a new Android project, not library this time. Add the library project to this new one.

In the main layout of this project, add a login button. When the user clicks the button, the user interface will switch to the login layout from our library. So, in the main activity, add the following code in the handler method of the login button:

Finally, don’t forget to declare the library activity in the manifest file of the client project. Open the AndroidManifest.xml from the client project and inside the application tag, add the following declaration: