Issue
I'm using a class that contains AsyncTask
to get JSON from my server which return different types of variables that vary depending on the situation (sometimes it return String
, sometimes Bool
etc). So what I'm trying to achieve is that to use the same class but changing the onPostExecute()
return value depending on the situation.
If my script return Bool
, the result changes to Boolean
etc. I would like to know is it possible to pass a class as parameters in AsynTask
method in Java? Or if there are any other better alternatives? Thanks in advance.
public class PHPConnecteur extends AsyncTask<String, Integer, myClass>{
@Override
protected void onPostExecute(final myClass result) {
//do something
}
}
Solution
The question is not clear. You have specified that you will get JSON from your server and it should return response in JSON format.
What do you mean the return types are vary sometimes?
If the values for the keys are vary in response JSON, then you convert the response String to JSON object and check for the appropriate data type like,
Object obj = jsonObject.get("some_key");
if (obj.getClass().equals(Boolean.class) {
// do your operation
}
// other checks goes here
Answered By - Uma Sankar
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.