I have this code inside my asynctask:
@Override
protected void onPreExecute() {
waitDialog = new ProgressDialog(context);
waitDialog.setTitle(R.string.wait_title);
waitDialog.setMessage(context.getString(R.string.wait_body));
waitDialog.setIndeterminate(true);
waitDialog.show();
}
@Override
protected Boolean doInBackground(Void... unused) {
Intent serviceIntent = new Intent(context, PublisherService.class);
saveSettings(false);
startService(serviceIntent);
return serviceIsRunning();
}
The dialog shows but while my service is starting (and it takes a few seconds) the progressdialog is frozen. If i use a simple SystemClock.sleep() inside my doInBackground() call it works fine.
Can someone tell me why is this happening and how to solve the issue?
Thanks
You should not start any services from threads or asynctasks. Service could start its own thread and perform all work there. Or it’s possible to bind to the service in onPreExecute() and call its methods from doInBackground. Read Local Service Sample here http://developer.android.com/reference/android/app/Service.html