Reputation: 926
I have a code placed in the onActivityResult()
but it is slowing my activity alot,
the code is to do Binarizng on Image.
I am confused whats to use AsyncTask
or Thread
,
can you help me with it
Upvotes: 2
Views: 165
Reputation: 517
Both AsyncTask and Thread, let you run background task on a different thread.
But AsyncTask provide you various callback, so that you can Update UI once the background task is done Or Canceled.
So, if your task involve any UI update; please use AsyncTask.
Upvotes: 1
Reputation: 93542
onActivityResult has nothing to do with threads or async tasks.
A thread allows your app to do two things at once. Doing so can be fairly risky (what if they write the same variables at the same time?). You need to be careful when using them.
An AsyncTask is a Thread that will automatically run some code on the main UI thread when its done. Its useful for running some code on a thread and then synchronizing results on the main thread.
onActivityResult is called when you are running a completely separate activity, either in your own app or in another person's. If you need to run another activity, this is the only way to get a result back from it. It has nothing to do with threads.
Upvotes: 1
Reputation: 54672
Use AsyncTask
AsyncTask Also uses Thread, but in a intelligent way. In android you can not update UI directly from a worker thread. But you can perform UI tasks from Asynctask. So this is a better option.
Upvotes: 1