我已经构建了一个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