성공적으로 실행되는 appwidget이 있습니다. 이제 전화가 재부팅 될 때 위젯은 모든 데이터를 잃어 버리고 홈 화면에 그냥 앉습니다. 전화가 재부팅 될 때 브로드 캐스트 리시버에서 위젯을 업데이트 할 수 없기 때문에 위젯의 구성 활동으로 연결되는 알림 을 만들었습니다. 사용자가 구성을 다시 설정하고 구성 활동을 종료 한 후에는 아무 것도 작동하지 않습니다. 유휴 위젯은 그냥 거기에 남아 있습니까? (사용자가 위젯을 삭제하고 위젯을 다시 만들어야합니다 ..) 제가 위젯 ID를 올바르게 수신하지 못하고 있거나 브로드 캐스트 리시버에서 잘못하고 있다고 가정하고 모든 코드를 위젯 메서드에서 onEnable? .. 위젯을 올바르게 새로 고치려면 어떻게해야합니까? 모든 위젯 업데이트는 서비스에서 수행된다는 점에 유의하십시오. 내가 boot_completed 활동을위한 방송 수신기에서이 코드가 그런데시스템 재시작에서 위젯을 다시 시작하고 업데이트하는 방법 android
는 :
public void onReceive(final Context context, Intent intent) {
String info = context.getResources().getString(R.string.restart_setting);
int[] allids = AppWidgetManager.getInstance(context).getAppWidgetIds(new ComponentName(context, MyWidgetProvider.class));
for(int appWidgetId:allids){
NotificationManager mnotifyManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notify = new Notification(R.drawable.icon, "Weather Update", System.currentTimeMillis());
notify.defaults = Notification.DEFAULT_SOUND;
notify.defaults = Notification.DEFAULT_VIBRATE;
Intent Settings = new Intent(context, WidgetConfigure.class);
Settings.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
PendingIntent pending = PendingIntent.getActivity(context, 0, weatherSettings, PendingIntent.FLAG_ONE_SHOT);
notify.setLatestEventInfo(context, "Weather Update", info, pending);
notify.flags = Notification.FLAG_AUTO_CANCEL;
notify.defaults = Notification.DEFAULT_ALL;
mnotifyManager.notify(WEATHER_NOTIFICATION_ID , notify);
}
}
최근에이 코드를 위젯주기의 onEnabled()로 이동하려고했지만 위젯을 새로 고치지 않았습니다. 전혀 가능합니까? ... – irobotxxx
yw는 appwidgetprovider 자체에 onReceive 메소드가 포함되어있는 경우 별도의 브로드 캐스트를 사용합니다. –
더 나은 방법으로 appwidgetprovider의 onReceive를 사용하여 위젯의 ID와 다른 구성 요소를 쉽게 처리 할 수 있습니다. –