我已經構建了一個appWidget,它在onEnabled()方法上註冊了一些服務。「清除內存」+ appWidget崩潰後服務不會重新啓動
問題是,在我使用內置任務管理器的Clean Memmory/Ram後,appWidget視圖崩潰(所有appWidgets TextView的文本都設置爲默認值(TextView)),服務停止運行並且從不重新啓動。
這隻會發生在一段時間後的小部件設置,如果我清潔Memmory/Ram的小部件設置後立即錯誤沒有發生,但我想這是有關任務管理器的清理RAM的方法。
最後,我的問題是:有沒有辦法告訴android系統重新啓動這些服務?作爲我通過市場下載的其他appWidgets似乎在此過程之後繼續正常工作。
會很高興的想法和解決方案!由於先進的,加:)
一些代碼,我使用:
在appWidget的onEnabled()方法:
@Override
public void onEnabled(Context context) {
super.onEnabled(context);
Intent newinIntent = new Intent(context, CallService_1x1.class);
context.startService(newinIntent);
newinIntent = new Intent(context, SmsService_1x1.class);
context.startService(newinIntent);
}
從服務的一個有些方法(其它服務內容有非常相似這是從他們的抽象方法):
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
// We want this service to continue running until it is explicitly
// stopped, so return sticky.
Log.d("SERVICE-SMS","CallMonitorService - onStartCommand created");
return START_STICKY;
}
@Override
public void onCreate() {
super.onCreate();
context = this.getApplicationContext();
Log.d("SERVICE-SMS","CallMonitorService created");
registerObserver();
}
@Override
public void onStart(Intent intent, int startId) {
super.onStart(intent, startId);
}
@Override
public void onDestroy() {
unregisterObserver();
super.onDestroy();
}
@Override
public IBinder onBind(Intent intent) {
return null;
}
/**
* Start the service to process that will run the content observer
*/
public static void beginStartingService(Context context) {
Log.d("SERVICE-SMS","CallMonitorService: beginStartingService()");
context.startService(new Intent(context, CallService.class));
}
/**
* Called back by the service when it has finished processing notifications,
* releasing the wake lock if the service is now stopping.
*/
public static void finishStartingService(Service service) {
Log.d("SERVICE-SMS","CallMonitorService: finishStartingService()");
service.stopSelf();
}
不工作,內存清理後Widget凍結... – Monzur