分類彙整: Android Apps Dev Competition

Controlling the Running Android Emulator

Adapt from
[1] http://developer.android.com/guide/developing/devices/emulator.html


Those keys that cannot be found on the emulated keyboard are in bold letters.

Emulated Device Key / Hardware Key / Effect Keyboard Key
Home HOME
Menu (left softkey) F2 or Page-up
Star (right softkey) Shift-F2 or Page-down
Back ESC
Call/dial F3
Hangup/end call F4
Search F5
Power button F7
Audio volulme up KEYPAD_PLUS, Ctrl-5
Audio volume down KEYPAD_MINUS, Ctrl-F6
Camera/Take a shot Ctrl-KEYPAD_5, Ctrl-F3
Switch to previous layout orientation (e.g. protrait or landscape mode) KEYPAD_7, Ctrl-F11
Switch to next layout orientation (e.g. protrait or landscape mode) KEYPAD_9, Ctrl-F12
Toggle cell networking on/off

F8

Toggle code profiling F9 (only with

-trace

startup option)

Toggle fullscreen mode Alt-Enter
Toggle trackball mode F6
Enter trackball mode temporarily (i.e. pressing key) Delete
DPad left/up/right/down KEYPAD_4/8/6/2
DPad center click KEYPAD_5
Onion alpha increase/decrease KEYPAD_MULTIPLY(*) / KEYPAD_DIVIDE(/)

Debugging in Android - 001

Observation

Cannot see new views(e.g. RadioGroup) after the textbox(i.e. edittext) while running my app with the following XML layout.

Code

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:padding="5dp">
   
    <EditText
        android:id="@+id/edittext"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"/>
   
   
    <RadioGroup android:id="@+id/people_radioGroup"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content">
      <RadioButton android:id="@+id/radio_red"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="Red" />
      <RadioButton android:id="@+id/radio_blue"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="Blue" />
    </RadioGroup>  
   
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Country" />
    <AutoCompleteTextView android:id="@+id/autocomplete_country"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="5dp"/>

</LinearLayout>

More Details

API Level: 8

Orientation: Vertical

Solution

The line

android:orientation="horizontal"

is incorrect.

It should be

android:orientation="vertical"

for veritcal orientation.

Android Activity Part 1

Adopt from

[1] http://developer.android.com/guide/topics/fundamentals.html


What is Activity?

From our daily experience, we need to perform some activities before we can finish a job. For instance, a dinner, you need to go to the supermarket, choose the ingredients, bring them home and cook them all. An activity composes of activities and the basic unit is the action.

In Android, the idea of activity restricts on a task completed on the screen. An activity represents a single screen with a user interface. For example, an email application might have one activity that shows a list of new emails, another activity to compose an email, and another activity for reading emails. Although the activities work together to form a cohesive user experience in the email application, each one is independent of the others. As such, a different application can start any one of these activities (if the email application allows it). For example, a camera application can start the activity in the email application that composes new mail, in order for the user to share a picture. [1]

How to implement Activities?

 

In simplest case, your activity needs to inherit from Activity. To create your activity, you need to override to onCreate method. Then, you need to put your view (technically, pass the reference of your view) in to the activity as the definition highlighted above.

public class MyActivity extends Activity {
    public void onCreate(Bundle savedInstanceState) {        
        super.onCreate(savedInstanceState);
        TextView textview = new TextView(this); // Create the view object within the activity class
        textview.setText("This is the a tab");
        setContentView(textview);
    }
}

public class MyActivity extends Activity {
    public void onCreate(Bundle savedInstanceState) {        
        super.onCreate(savedInstanceState);
        TextView textview = (TextView)findViewById(R.id.textview); // Get the reference from project resource (the layout is defined in XML)
        textview.setText("This is the a tab");
        setContentView(textview);
    }
}

Android - Intent, Activity, Service, Broadcast Receiver, Content Provider

Adopt from :

http://developer.android.com/guide/topics/fundamentals.html

http://developer.android.com/guide/basics/what-is-android.html

Some of the core libraries are listed below:

  • System C library - a BSD-derived implementation of the standard C system library (libc), tuned for embedded Linux-based devices
  • Media Libraries - based on PacketVideo's OpenCORE; the libraries support playback and recording of many popular audio and video formats, as well as static image files, including MPEG4, H.264, MP3, AAC, AMR, JPG, and PNG
  • Surface Manager - manages access to the display subsystem and seamlessly composites 2D and 3D graphic layers from multiple applications
  • LibWebCore - a modern web browser engine which powers both the Android browser and an embeddable web view
  • SGL - the underlying 2D graphics engine
  • 3D libraries - an implementation based on OpenGL ES 1.0 APIs; the libraries use either hardware 3D acceleration (where available) or the included, highly optimized 3D software rasterizer
  • FreeType - bitmap and vector font rendering
  • SQLite - a powerful and lightweight relational database engine available to all applications

A central feature of Android is that one application can make use of elements of other applications (provided those applications permit it).

An activity presents a visual user interface for one focused endeavor the user can undertake.

A service doesn't have a visual user interface, but rather runs in the background for an indefinite period of time.

A broadcast receiver is a component that does nothing but receive and react to broadcast announcements.

A content provider makes a specific set of the application's data available to other applications.

Content providers are activated when they're targeted by a request from a ContentResolver. The other three components — activities, services, and broadcast receivers — are activated by asynchronous messages called intents. An intent is an

<a href="http://developer.android.com/reference/android/content/Intent.html">Intent</a>

object that holds the content of the message. For activities and services, it names the action being requested and specifies the URI of the data to act on, among other things. For example, it might convey a request for an activity to present an image to the user or let the user edit some text. For broadcast receivers, the Intent object names the action being announced. For example, it might announce to interested parties that the camera button has been pressed.

A content provider is active only while it's responding to a request from a ContentResolver. And a broadcast receiver is active only while it's responding to a broadcast message. So there's no need to explicitly shut down these components.

Activities, on the other hand, provide the user interface. They're in a long-running conversation with the user and may remain active, even when idle, as long as the conversation continues. Similarly, services may also remain running for a long time. So Android has methods to shut down activities and services in an orderly way:

  • An activity can be shut down by calling its
    <code><a href="http://developer.android.com/reference/android/app/Activity.html#finish()">finish()</a>

    method. One activity can shut down another activity (one it started with

    startActivityForResult()

    ) by calling

    <code><a href="http://developer.android.com/reference/android/app/Activity.html#finishActivity(int)">finishActivity()</a>

    .

  • A service can be stopped by calling its
    <code><a href="http://developer.android.com/reference/android/app/Service.html#stopSelf()">stopSelf()</a>

    method, or by calling

    <code><a href="http://developer.android.com/reference/android/content/Context.html#stopService(android.content.Intent)">Context.stopService()</a>

    .

The manifest is a structured XML file and is always named AndroidManifest.xml for all applications. It does a number of things in addition to declaring the application's components, such as naming any libraries the application needs to be linked against (besides the default Android library) and identifying any permissions the application expects to be granted.