-1

I've coded an Android widget with two buttons. If i start the "Activity" all works fine and i can click on those buttons. But if i lock the phone, the process dies after a few seconds

enter image description here

and i try to click on those buttons again, nothing happens, except the LOGCAT:

I/ActivityManager: filter receiver for action = ButtonRefresh


updateAppWidget, called via @Override onUpdate(...):

private final static String BUTTON_REFRESH = "ButtonRefresh";

public static void updateAppWidget(final Context context, final AppWidgetManager appWidgetManager,
                                   final int appWidgetId) {

    final RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.myclasslayout);

    //Click listener depending on @this (getPendingSelfIntent)
    views.setOnClickPendingIntent(R.id.button_refresh, getPendingSelfIntent(context, BUTTON_REFRESH));

    [...]

    appWidgetManager.updateAppWidget(appWidgetId, views);
}


getPendingSelfIntent():

private static PendingIntent getPendingSelfIntent(Context context, String action) {
    Intent intent = new Intent(context, MyClass.class);
    intent.setAction(action);
    return PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
}


onReceive():

@Override
public void onReceive(Context context, Intent intent) {
    super.onReceive(context, intent);

    if (BUTTON_REFRESH.equals(intent.getAction())) {
        Log.i("MyLogtag", "Refresh"); //This never shows up in LOGCAT
    }
}


AndroidManifest.xml:

[...]
<receiver android:name=".MyClass">
    <intent-filter>
        <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
    </intent-filter>
    <meta-data
        android:name="android.appwidget.provider"
        android:resource="@xml/myclass_info" />
</receiver>
[...]

onReceive never gets called when app process is dead...

Sebastian Schneider
  • 4,896
  • 3
  • 20
  • 47

1 Answers1

0

I got it...

i have to change

private final static String BUTTON_REFRESH = "ButtonRefresh";

to

private final static String BUTTON_REFRESH = "com.example.mypackage.BUTTON_REFRESH";

and AndroidManifest:

 <receiver android:name=".MyClass">
<intent-filter>
    <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
    <action android:name="com.example.mypackage.BUTTON_REFRESH"/>
</intent-filter>
<meta-data
    android:name="android.appwidget.provider"
    android:resource="@xml/myclass_info" />
</receiver>
Sebastian Schneider
  • 4,896
  • 3
  • 20
  • 47