title: How to Return Different Objects via Asynctask in Android
body: <p>I figured this must be a common question, but I surprisingly couldn't find an answer, so maybe my entire structure is terribad...</p>
  
  <p>I have an activity which downloads values/states of a game from a web service via AsyncTask. These values are used to update a custom view.</p>
  
  <p>Once the view is created, various events from the view launch an AsyncTask to download other information.</p>
  
  <p>This is functional, but the problem is I now have half a dozen AsyncTask classes in the activity with almost identical code. The only difference is the type of object that is returned (which is based on the json from the web service) and the method that is called from <code>onPostExecute()</code>. </p>
  
  <p>How can I use just two AsyncTask (one for post and one for get) without knowing what type of json object will be returned by the web service?</p>
  
  <p>In a similar vein, how can I determine the type of object returned by the web service? The web service, if there is a problem, will return a json string that correlates to an ErrorMessage object rather than (for example) a GameData object. </p>
  
  <p>Should I be using <code>switch</code> and <code>instanceof</code> in <code>onPostExecute()</code> somehow? Callbacks maybe?</p>