Monday, April 12, 2010

Creating an Android Activity with no UI

Since I released 'Dimmer (Night Mode)' into the Android Market I've had a few Android devs asking how to create Activity based applications with no UI.
The answer is that you need to set the activity theme in the manifest, for dimmer I use:

android:theme="@android:style/Theme.Translucent.NoTitleBar"

like this in AndroidManifest.xml:

<activity android:name=".Dimmer"
android:theme="@android:style/Theme.Translucent.NoTitleBar"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>


The latest set of activity themes are defined in /res/values/themes.xml in the Android source here.

Which may not be particularly user friendly but it also demonstrates how you can create your own activity themes in your own /res/values/themes.xml if you so desire.

Note I'm not using the theme 'NoDisplay' as I do actually show notifications on the screen as the Activity is going about its business.