Hello I have an intent as below that starts a service
public void startAlarmService() {
Intent i = new Intent();
i.setAction("me.application.AlarmService");
startService(i);
}
This method is called when a checkbox is checked. However, when it gets checked, the UI freezes for like 5 seconds..
I tried to call the above method by running a new Thread, and then by using AsyncTask but both didn’t work and it took also like 5 seconds to run since for example I put a progress dialog and the UI froze before showing the progress dialog.
How can I make sure that the UI does not freeze on start this service?
Thank you for you help.
Edit: Service Code: Download part using async task:
asyncDownload aCall = new asyncDownload(getApplicationContext(),this);
boolean result = aCall.execute().get();
return result;
You are firstly creating an
AsyncTaskand later using it’sget()method, which blocks main thread. Do it properly – background work indoInBackground(Params...), then update UI inonPostExecute(Result), which is called in main thread again – instead of usingget().