Android code , Android Phone, Android Developers

Android code , Android Phone, Android Developers and New Google Android Technologies

Archive for October, 2010

.java File

Posted by admin October - 29 - 2010 - Friday ADD COMMENTS

<activity>.java File The file in the src directory that you will spend the most time with
is <activity>.java (HelloWorldText.java in this example), which is created by the Android
plugin and named to match the Activity name that you specified in the New Android
Project wizard. Unlike most of the files you have examined in this section, this file is
completely editable; in fact, it will do very little for you if you do not modify it with
your code.
After briefly looking at what is in your HelloWorldText.java file as it is created by the
Android plugin, you will then edit the file to create your first Android Activity.

package android_programmers_guide.HelloWorldText;
import android.app.Activity;
import android.os.Bundle;

public class HelloWorldText extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
}
}
The three lines at the top of the file are the standard preprocessor directives—that is,
as in most programming languages, statements that are directives to the compiler to run
before the application process. In this case, you have the definition and inclusion of your
package android_programmers_guide.HelloWorldText.
The next two lines import specific packages from the Android SDK via android.jar:
import android.app.Activity;
and

import android.os.Bundle;
These lines tell the project to include all the code from the imported packages before all
the code in your application. These two lines are critical for your base Android application
and should not be removed..

Android Open Source Project

Posted by admin October - 16 - 2010 - Saturday ADD COMMENTS
YouTube Preview Image

R.java File

Posted by admin October - 14 - 2010 - Thursday ADD COMMENTS

R.java File The file R.java is an auto-generated file that is added to your application by the Android plugin. This file contains pointers into the drawable, layout, and values directories (or the items within the directories, as is the case with strings and icons). You should never have to modify this file directly. You will be referencing R.java in most of your applications. The code that was auto-generated for the HelloWorldText application follows:

/* AUTO-GENERATED FILE.  DO NOT MODIFY.
*
* This class was automatically generated by the
* aapt tool from the resource data it found.  It
* should not be modified by hand.
*/
package testPackage.HelloWorldText;
public final class R {
public static final class attr {
}
public static final class drawable {
public static final int icon=0x7f020000;
}
public static final class layout {
public static final int main=0x7f030000;
}
public static final class string {
public static final int app_name=0x7f040000;
}
}

NOTE
The comment section of the R.java file provides an explanation of the origin of the file. It states that the file was created by the aapt tool. In Chapter 6, when you create a command-line–only version of the Hello World! application, you will use command-line tools to create all of the auto-generated files.

Directories in android

Posted by admin October - 4 - 2010 - Monday ADD COMMENTS

Directories

There are also three directories in the project root—res, assets, and src—each of which has a distinct purpose. These directories play an integral part in the operation of your application.

res Directory

The res directory is where your in project resources are held and compiled into your application. When you create a new Android project, the res directory contains three subdirectories: drawable, layout, and values. You will use the drawable and layout directories in many of your projects to hold and display images and layouts respectively, whereas the values directory holds string globals that can be used throughout your

application.

NOTE

A reference to the res directory and its contents is contained by the R.java file, located in the src directory. This file is covered in much more detail later in the chapter. The drawable directory contains actual image files that your application can use and reference. The layout directory holds an XML file, main.xml, that is referenced by your application when building its interface. In most of the applications in this book, you will

be editing the main.xml file included in the layout directory. This will allow you to insert Views into the application’s visual layout and display them. An unaltered main.xml file contains the following code:

<?xml version=”1.0″ encoding=”utf-8″?>

<LinearLayout xmlns:android=http://schemas.android.com/apk/res/android

android:orientation=”vertical”

android:layout_width=”fill_parent”

android:layout_height=”fill_parent”

>

<TextView

android:layout_width=”fill_parent”

android:layout_height=”wrap_content”

android:text=”Hello World, HelloWorldText”

/>

</LinearLayout>

The last directory under res, values, holds an XML file named strings. The strings.xml file is used to hold global string values that can be referenced by your application.

assets Directory

The assets directory is used to hold raw asset files. The files contained in the assets directory can include audio files for streaming and animation assets. we will not use any audio assets in the applications for this book because the beta audio drivers for the Android Emulator are not yet optimized.

src Directory

The src directory contains all the source files for your project. When your project is first created, it will contain two files, R.java and <activity>.java (in this example,

HelloWorldText.java), described next.

NOTE

<activity>.java is always named according to your Activity name.