Just An Application

August 22, 2009

A Standalone Android Runtime: Launching HelloWorld The Easy Way

Filed under: Android, Java, Mobile Java, Standalone Android Runtime — Tags: , , , — Simon Lewis @ 9:03 am

There is a considerably easier way of getting an application launched and that is to make it the home application. This can be done by modifying the application manifest, which is rather simpler than modifying the internals of the ActivityManagerService.

The standard home application is the Launcher which you can find here

    $(ANDROID_SRC)/packages/apps/Launcher

If you look at the application manifest (the file AndroidManifest.xml) you will see two category elements in the intent-filter of the activity, one named

    android.intent.category.HOME

and the other

    android.intent.category.DEFAULT

It is the presence of those two category elements which make the Launcher the home application.

Adding these to the HelloWorld application manifest gives us the following

    <?xml version="1.0" encoding="utf-8"?>
    <manifest 
          xmlns:android="http://schemas.android.com/apk/res/android"
          package="standalone.helloworld"
          android:versionCode="1"
          android:versionName="1.0">
        <application android:icon="@drawable/icon" android:label="@string/app_name">
            <activity android:name=".HelloWorldActivity"
                  android:label="@string/app_name">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.HOME"/>
                    <category android:name="android.intent.category.DEFAULT"/>
               </intent-filter>
            </activity>
        </application>
        <uses-sdk android:minSdkVersion="3" />
    </manifest> 

If we put the new version of the HelloWorld package in the data app directory and and start the SystemServer then HelloWorld gets launched automatically by the ActivityManager.

Here’s part of the Main log.

...

21-08-09 17:07:58: 22001: DEBUG: PowerManagerService system ready!
21-08-09 17:07:58: 22001: DEBUG: ActivityManager Start running!
21-08-09 17:07:58: 22001: INFO: ActivityManager Starting activity: Intent { ... }

Having started the ActivityManager begins launching HelloWorld as the home application . The Intent is

    {
        action=android.intent.action.MAIN 
        categories={android.intent.category.HOME} 
        flags=0x10000000 
        comp={standalone.helloworld/standalone.helloworld.HelloWorldActivity}
    }

The flag is Intent.FLAG_ACTIVITY_NEW_TASK as before.

21-08-09 17:07:59: 22001: INFO: ActivityManager Start proc standalone.helloworld for activity standalone.helloworld/.HelloWorldActivity: pid=25001 uid=10000 gids={}
21-08-09 17:07:59: 22001: WARN: ActivityManager Unable to start service Intent { ... } }: not found
21-08-09 17:07:59: 22001: ERROR: LockPatternKeyguardView Failed to bind to GLS while checking for account
21-08-09 17:07:59: 22001: WARN: StatusBar Icon not found in : 0
21-08-09 17:07:59: 22001: DEBUG: LocationManagerService PowerStateBroadcastReceiver: Battery changed
21-08-09 17:08:00: 22001: DEBUG: StatusBar updateResources
21-08-09 17:08:00: 22001: DEBUG: LocationManagerService PowerStateBroadcastReceiver: Screen on
21-08-09 17:08:00: 22001: DEBUG: LocationManagerService updateWakelockStatus(): true
21-08-09 17:08:00: 22001: DEBUG: LocationManagerService Cancelling existing alarm
21-08-09 17:08:00: 22001: DEBUG: LocationManagerService No need for alarm
21-08-09 17:08:00: 22001: DEBUG: LocationManagerService Can't release wakelock again!
21-08-09 17:08:02: 22001: INFO: ActivityManager Displayed activity standalone.helloworld/.HelloWorldActivity: 3152 ms

The rest of the log is as before at this point in the start up and then the application is running.

A section of the Event log.

21-08-09 17:07:58: 22001 11664372 boot_progress_ams_ready[3040]	time 7085 milliseconds
21-08-09 17:07:59: 22001 11664372 am_create_task[30004]         Task ID 2 
21-08-09 17:07:59: 22001 11664372 am_create_activity[30005]     Token 2412794 Task ID 2 Component Name standalone.helloworld/.HelloWorldActivity Action android.intent.action.MAIN MIME Type  URI  Flags 268435456 
21-08-09 17:07:59: 22001 11664372 am_proc_start[30014]          PID 25001 UID 10001 Process Name standalone.helloworld Type activity Component standalone.helloworld/.HelloWorldActivity 
21-08-09 17:07:59: 22001 15182069 am_proc_bound[30010]          PID 25001 Process Name standalone.helloworld 
21-08-09 17:07:59: 22001 15182069 am_restart_activity[30006]	Token 2412794 Task ID 2 Component Name standalone.helloworld/.HelloWorldActivity 
...
21-08-09 17:08:01: 25001 15069394 am_on_resume_called[30022]	Component Name standalone.helloworld.HelloWorldActivity 
21-08-09 17:08:02: 22001 8778710 activity_launch_time[30009]	Token 2412794 Component Name standalone.helloworld/.HelloWorldActivity time 3152 milliseconds 

Copyright (c) 2009 By Simon Lewis. All Rights Reserved.

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Blog at WordPress.com.