Android Programming Tutorials

(Romina) #1
More Home Cooking

You will notice that the onHandleIntent() method is almost identical to the


current onUpdate() method in AppWidget. The differences are that all


references to ctxt are replaced with this (since the IntentService is a


Context) and that we need to obtain an AppWidgetManager rather than use one


passed into us. But, since onHandleIntent() is run on a background thread,


we can take as much time as is necessary.


Then, add WidgetService to the manifest:


<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="apt.tutorial"
android:versionCode="1"
android:versionName="1.0">
<application android:label="@string/app_name">
<activity android:name=".LunchList"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<meta-data android:name="android.app.searchable"
android:resource="@xml/searchable" />
<meta-data android:name="android.app.default_searchable"
android:value=".LunchList" />
</activity>
<activity android:name=".DetailForm">
</activity>
<activity android:name=".EditPreferences">
</activity>
<receiver android:name=".AppWidget"
android:label="@string/app_name"
android:icon="@drawable/icon">
<intent-filter>
<action
android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/widget_provider" />
</receiver>
<service android:name=".WidgetService" />
</application>
</manifest>

329
Free download pdf