android.os.NetworkOnMainThreadException . Need to use async task?

I guess you are trying to peform some Network operation on your main thread

NetworkOnMainThreadException from the Docs

The exception that is thrown when an application attempts to perform a
networking operation on its main thread.

UPDATE:

Its Better to use AsyncTask

private class MyAsyncTask extends AsyncTask<Void, Void, Void>
    {

        ProgressDialog mProgressDialog;
        @Override
        protected void onPostExecute(Void result) {
            mProgressDialog.dismiss();
        }

        @Override
        protected void onPreExecute() {
            mProgressDialog = ProgressDialog.show(ActivityName.this, 
                                            "Loading...", "Data is Loading...");
        }

        @Override
        protected Void doInBackground(Void... params) {
           // your network operation
            return null;
        }
    }

Leave a Comment