I created an appWidget that registers some services in the onEnabled () method.
The problem is that after I use the built-in Clean Memmory / Ram task manager, the appWidget application will work (all AppWidgets TextView text files are installed by default (TextView)), and the services stop working and never restart.
This only happens after a while when the widget is installed, and if I clean Memmory / Ram immediately after installing the widget, an error will not occur, but I think that this is due to the task manager method of cleaning the RAM.
So finally, my question is: is there a way so that the Android system can restart these services? since the other applications that I downloaded through the market seem to continue to work after this procedure.
I will be happy for ideas and solutions! Thanks, advanced, Gal :)
some code i use:
onEnabled () method in appWidget:
@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); }
Some methods from one of the services (other services are very similar, since this is from their abstract method):
@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(); }