I have an Android Widget that uses web services to retrieve and display the data on the widget. The widget has a configuration activity that extends PreferenceActivity
. The configuration activity starts up as soon as the widget is installed, which is the desired behavior for this widget.
The problem is, whenever a widget is added to the home screen, the widget attempts to update iteself before the configuration activity is started/completed which may potentially lead to a long delay (several seconds). The configuration activity should occur before the widget attempts to update itself anytime a new widget is added.
Here is the sequence of events that I'm seeing in LogCat when a widget is added:
- Widget.onRecive: action = APPWIDGET_ENABLED
- Widget.onEnabled
- Widget.onReceive: action = APPWIDGET_UPDATE
- Widget.onUpdate: Widget Service is started.
- WidgetService.onStartCommand: Potentially long running work which will delay the configuration activity from being immediately shown.
- WidgetConfiguration.onCreate
- Widget.onReceive: action = APPWIDGET_UPDATE
- Widget.onUpdate: Widget Service is started again
- WidgetService.onStartCommand: Potentially long running work is performed again.
What's happening is that when a widget is added, the service will start up before the configuration view has been shown.
Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="xxx.xxx.xxxwidget"
android:versionCode="1"
android:versionName="@string/app_version" >
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:debuggable="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<receiver android:name="xxxWidget" >
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/widget_info" />
</receiver>
<activity android:name="xxxWidgetConfigure" >
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" />
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name="xxxWidgetService" />
</application>
</manifest>
Question
Is there a way to force the configuration activity to be shown before the system attempts to add the widget to the home screen?