I was working my way through the Android developer documents at developer.android.com and had a little trouble getting the example code to run without any alterations in the emulator and frankly, you have to know this stuff if you’re going to code anything serious on the android platform.

The troubles starts at this code snippet:

Android Developers Code Snippet

This code didn’t work for me…

So I started to dig into the developer docs looking at the AsyncTask Class to find out just what might be wrong and found this:

AsyncTask’s Generic Types specifies three input types, I guess you need to modifiy the above code to look more like mine to get this to work.

Working Android Code Snippet for Network Operations

This worked for me!

 

So from what i understand the AsyncTask accepts three paramiters:

Params, Progress, and Result.  so instead of just having the DownloadWebpageTask method extend only AsyncTask i decided to key in the params using <String, Void, String> for the parameters.  Now the developer docs says you can just insert “Void” in all the fields.  I used a String data type for the Params… as the docs say this will be the type of parameter sent to the task upon execution.  For Progress I inserted the optional “Void” parameter and then used the String data type for the Result as I knew the function would be returning a string.

Like the above screen shot.  Worked like a charm!

 

 

Subscribe to my email marketing list.

Subscribe To My Newsletter

Unlock Your Creative Potential! Join Now to Receive Inspiring Art News and Expert Photography Tips!

You have Successfully Subscribed!

Pin It on Pinterest

Share Art

Please share this with your friends!