Skip to content Skip to sidebar Skip to footer

Trying To Use Async With Image Upload To Webserver Android?

I am trying to use Async to be more efficient and to allow for image uploads to my webserver I have tried various methods but there is always something not working... Here is my la

Solution 1:

I see many several problems here. First, you almost never (if ever) want to call runOnUiThread() from AsyncTask. Every method of AsyncTask runs on the UI except for doInBackground() so this usually isn't needed and often causes problems. Update the UI with the correct methods depending on what you are doing.

Second, I think you misunderstand what doInBackground() is returning. Its result is returned to onPostExecute() which is the 3rd param in your class declaration

privateclassdoFileUploadextendsAsyncTask <String, Void, String> {

So this means that onPostExecute() (which I don't see you overriding) should expect a String and that is what doInBackground() should return. So you should convert your return variables to String if you want to pass a String to onPostExecute()

AsyncTask Docs

Typically

progressDialog.dismiss();

is called in onPostExecute() and

progressDialog.show();

would be called in onPreExecute() when using an AsyncTask. Then you don't have to create a new Thread in your onClick().

Post a Comment for "Trying To Use Async With Image Upload To Webserver Android?"