I have a a service class which includes an Async task. In the doInBackground and onPostExecute I call some methods which are in the service class but outside the Async task. When these methods get called will they still be in the thread created by the Async task and therefore not interfering with the main UI.
To illustrate my lack of understanding a bit more should I try to get almost everything that the service class does into the Async task. For example the service starts up as the result of an alarm and in the onStartCommand sets a repeating alarm (this is as Reto Meire’s Earthquake example)and creates a database. Would it make sense to move the code for these two operations into the onPreExecute part of the Async task?
No need to do that.. make sure that the method which you want to run in background is called from
doInBavkground().. rest you can put inpostExecute…. the snippet which you want to run after the backGround task should be inPostExecute(). If You call methods fromdoInBackground()they still run on background thread.. does’t matter where they are.. and if you call it fromonPostExecute()then it will run on other thread which ofcourse can make changes in your display.. just like showing dialog etc…