What I am trying to achieve is as follows – I have a java class which calls a URL (passed to it), which returns JSON, which calls a call back from within the calling activity which processes the data.
This allows reusability of the aSyncTask code.
In some cases I needed to pass post data to the URL being called, so I created a new method with allows me to add data
HashMap<String, String> mData;
public void AddDataToPost(HashMap<String, String> data) {
mData = data;
}
Then I pass this data with my httprequest.
My question is as follows.
I want to be able to pass any type of data in. For example a HashMap.. but i cannot do this because I have head to specify the bit when I initialized the var.
I could create an addHashMap method, but the same problem arises as the var is initialized as String, String.
How would I go about reusing code whilst allowing the passing of any data form?
THanks
You could define your class to use raw types, e.g.
You could then do this:
Note though that you cannot pass primitives so you would have to box integers and so on.
See this tutorial on Java Generics.
http://docs.oracle.com/javase/tutorial/java/generics/types.html