Reputation: 4595
I have an AppWidgetProvider
that should fire a Service in order to perform the requested updates on the App Widget.
The point is that the Service UpdateService
apparently never starts. Indeed I have put a Log in the onStartCommand
of the Service and I can see that onStartCommand
never gets called.
Please note I have two Services in my Application:
<service android:name="ScheduledService" />
<service android:name="UpdateService" />
Any help very much appreciated. Thanks
That's my relevant code:
public class AppWidget extends AppWidgetProvider {
@Override
public void onUpdate(Context ctxt, AppWidgetManager mgr, int[] appWidgetIds) {
Intent i = new Intent(ctxt, UpdateService.class);
i.putExtra("widgetsids", appWidgetIds);
Log.e("","onUpdate di AppWidget");
// --> HERE I TRY TO START THE SERVICE <--
ctxt.startService(i);
}
public static class UpdateService extends Service {
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
// --> onStartCommand NEVER GEST CALLED <---
Log.e("","onStartCommand di AppWidget");
int[] appWidgetIds = intent.getIntArrayExtra("widgetsids");
final int N = appWidgetIds.length;
AppWidgetManager manager = AppWidgetManager.getInstance(this);
// Perform this loop procedure for each App Widget that belongs to
// this provider
for (int i = 0; i < N; i++) {
int appWidgetId = appWidgetIds[i];
RemoteViews view = buildUpdate(getApplicationContext(),
appWidgetId);
// Tell the AppWidgetManager to perform an update on the current
// app widget
manager.updateAppWidget(appWidgetId, view);
}
return (START_NOT_STICKY);
}
This is my manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.stocktickerwidget"
android:versionCode="1"
android:versionName="1" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<supports-screens
android:anyDensity="true"
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:xlargeScreens="true" />
<application
android:debuggable="true"
android:icon="@drawable/ic_launcher"
android:label="TestWidget" >
<receiver
android:name=".AppWidget"
android:icon="@drawable/cw"
android:label="AppWidget" >
<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>
<activity
android:name=".WidgetActivity"
android:theme="@android:style/Theme.NoDisplay" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name="PollReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<service android:name="ScheduledService" />
<service android:name="UpdateService" />
</application>
Upvotes: 0
Views: 268
Reputation: 6526
In your manifest, try including the package name, such as:
<service android:name="com.mypackage.ScheduledService" />
<service android:name="com.mypackage.UpdateService" />
Otherwise, make sure your onUpdate method gets called.
EDIT: Above applies when you have your service in a seperate file. Since you included it as a nested class, you can write:
<service android:name=".AppWidget$UpdateService" />
Upvotes: 2