간단한 메모 위젯 앱을 만들고 있습니다. 일부 텍스트를 작성하고 SharedPreference에 저장하십시오. 모든 것이 정상입니다 .. 내 휴대 전화가 재부팅되면 앱 위젯이 기본값으로 설정됩니다.휴대 전화를 재부팅 할 때 appWidgetProvider에서 데이터를 복원하는 방법은 무엇입니까?
내가 Boot_Complete에 대해 뭔가해야한다고 들었습니다. 그래서 Manifest에 Boot_Complete Permission과 Intent-Filter를 추가합니다. 하지만 내 전화가 재부팅 될 때 내가 어떻게 onUpdate를 호출 할 수 있는지 전혀 모르겠다. 내 소스는
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
int[] appWidgetIds) {
super.onUpdate(context, appWidgetManager, appWidgetIds);
for(int i=0; i<appWidgetIds.length; i++){
int widgetId = appWidgetIds[i];
Intent intent = new Intent(context, MyAppPostItActivity.class);
intent.putExtra("widgetId", widgetId);
PendingIntent pending = PendingIntent.getActivity(context, widgetId, intent, PendingIntent.FLAG_UPDATE_CURRENT);
RemoteViews remote = new RemoteViews(context.getPackageName(), R.layout.widget);
remote.setOnClickPendingIntent(R.id.layout, pending);
appWidgetManager.updateAppWidget(widgetId, remote);
}
}//onUpdate
@Override
public void onReceive(Context context, Intent intent) {
super.onReceive(context, intent);
if(intent.getAction().equals("android.intent.action.BOOT_COMPLETED")){
//I guess I should Call the onUpdate In here!! But I don't know how..
}
}
boot_complete 후
, 내가 어떻게 내 위젯의 데이터를 복원 할 수 있습니다 ..이 .. 가 onReceive 부분을 참조하시기 바랍니다인가? 나는 어떤 제안이나 단서 또는 샘플 희망 .. ~ 덕분에 많이 ~!