Currently i am using Handlers to call web service methods to make it run in background. The problem is its taking more time to give the response, it seems to be more expensive in terms of performance. Now i plan to go for the Async Calls, which will be the best one? What are differences between Handlers and Async Calls in Android? Please help me to come up with a best solution.
For your reference I am giving some code snippets here
signIn.setBackgroundResource(R.drawable.signin_press);
changeImage=new Runnable(){
public void run(){
signIn();
}
};
signinHandler.post(changeImage);
When clicking the Sign in button i am calling this method, it looks like the UI is hanged for few minutes before calling the method. In this method, two expensive web services calls are involved to authenticate and register the user. How i can normalize the slowness of the app. Help me.
There are certain advantages to using
ThreadandHandlerrespectively to usingAsyncTaskit really depends on your usage and the profiling of those benefits vs detriments will likely come down to you.I would recommend the article Painless Threading for a little understanding of threading on Android.
EDIT for additional info in question.
If we adapt the code from the Painless Threading article that was linked you can get something like so.
In the TODO you need to continue or notify execution, I don’t know what is currently handled in
signIn()so if that crosses the UI thread it will have to be refactored.