J'ai codé un widget Android
avec deux boutons. Si je commence l'activité, tout fonctionne correctement et je peux cliquer sur ces boutons. Mais si je verrouiller le téléphone, le processus meurt après quelques secondesImpossible de cliquer sur le widget Android après la fin du processus de l'application
et je tente de cliquer sur les boutons à nouveau, rien arrive, à l'exception du LOGCAT
:
I/ActivityManager: filter receiver for action = ButtonRefresh
updateAppWidget
, appelé 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 jamais appelée lors du processus d'application est dead
...