I need to stop a pair of services just before I delete a database. The services are accessing the database, and if they are not stopped, the app will crash.
Like so:
stopService(new Intent(CurrentClass.this, FirstService.class));
stopService(new Intent(CurrentClass.this, SecondService.class));
CurrentClass.this.deleteDatabase(MyDatabaseHelper.DATABASE_NAME);
As far as I know, the problem is that stopService is asynchronous. How can I force my services to stop before my database is deleted?
Thanks!
As far as I know, the exact timing of the service being destroyed is up to Android and may not be immediate..so keeping this in mind… i think it is better that you check in your service if your database is available.. and then access it…if you think.. you shouldn’t be doing this checking if databse is available,always ,in the service… then before you call
broadcast an intent that service is asked to stop and in your service implement a listener ,and in onreceive of that listener start the method for checking if the database is available…. like this.. for example..
and in onreceive of your broadcast receiver