I have a fragment in which I start the thread. In this thread I get a object and after that I want to pass the object to the main thread. What shall I do for this?
public class IFragment extends Fragment {
private void getRecentlyTag(){
new Thread(){
@Override
public void run() {
HttpURLConnection urlConnection = null;
try {
URL url = new URL(Constants.API_URL);
urlConnection = (HttpURLConnection) url
.openConnection();
urlConnection.setRequestMethod("GET");
urlConnection.setDoInput(true);
urlConnection.connect();
String response = Tools.streamToString(urlConnection
.getInputStream());
JSONObject jsonObj = (JSONObject) new JSONTokener(response)
.nextValue();
}catch(Exception exc){
exc.printStackTrace();
}finally {
if(urlConnection!=null){
try{
urlConnection.disconnect();
}catch(Exception e){
e.printStackTrace();
}
}
}
// mHandler.sendMessage(mHandler.obtainMessage(what, 2, 0));
}
}.start();
}}
I need to pass jsonObj back to the main thread?