0

I am a beginner in android app developing.

I have to use ping test in my app for checking available internet connection as I have found this method very useful, but I read at many places that I should use AsyncTask() method or Handler() method as ping test on UI thread may freeze my app.

But I am not getting the difference between those two to decide which one I should use. I found that in AsyncTask, I have methods like doInBackground() and onPostExecute which helps in interaction with UI thread and processes run in another thread.

But I am not getting such methods in Handler() method.

Handler handler = new Handler();
Runnable runnable =new Runnable() {
 @Override
 public void run() {
     handler.postDelayed(this,1000);
 }
};
handler.post(runnable);
  1. I am not getting which method in Handler() is running in background and which method are helpful for making the app run in background like I found in AsyncTask().
  2. I am not understanding the difference between those two.
Swr7der
  • 849
  • 9
  • 28

1 Answers1

1

Simple and Main Difference between them is

An AsyncTask is used to do some background Task and publish the result to the UI thread with/without progress update.

If you're not concerned with UI, then a Handler/Thread are more appropriate.

Abhishek Patel
  • 4,280
  • 1
  • 24
  • 38