Home Ask Login Register

Developers Planet

Your answer is one click away!

HeisenBerg February 2016

update textviews on different fragments based on asyntask result

I've an activity which on create calls an async task.

public class Sync extends BaseActivity implements OnClickListener{

    public void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub

Now the result of the async task determines which fragment to load inside the activity which I was able to do. But could not figure how to update the textviews inside the fragments. Please take a look at the onPostExecute() method. After loading a fragment how do I update the TextViews based on the result?

public class CheckForDeviceTask extends AsyncTask<String, Integer, String> {
    private static final String TAG = "CheckForDeviceTask";
    public static final int CONNECTED_DEVICE_EXISTS = 1;
    public static final int WAITING_TEMP_PASSWORD = 2;
    private Activity activity;

    // private DialogFragment dialogFragment;

    public CheckForDeviceTask(Activity activity) {
        this.activity = activity;

    protected void onPreExecute() {
        // FragmentManager fm = activity.getFragmentManager();
        // dialogFragment = ProgressDialogFragment.newInstance("Saving");
        // dialogFragment.show(fm, "dialog");

    protected String doInBackground(String... params) {
        if (GCHUtils.isConnected(activity)) {
            return GCHUtils.httpGet(RestApiPaths.CHECK_FOR_DEVICE
                    + params[0].toString());
        return null;

    protected void onPostExecute(String result) {
        // dialogFragment.dismiss();
        try {
            if (result != null && !result.isEmpty()) {
                Map<String, Object> resultMap = MapUtility.jsonToMap        


App Crazy February 2016

First put the data you get eg email and name, in a bundle and send the bundle as arguments to the destination Fragment,as shown below:-

          `Bundle bundle = new Bundle();
            bundle.putSerializable("email ", email );
            bundle.putBoolean("name", name);

In the destination Fragment get the data as follows:

                  `String email=getArguments().getString("email");
                   String name=getArguments().getString("name");`

Post Status

Asked in February 2016
Viewed 2,819 times
Voted 13
Answered 1 times


Leave an answer

Quote of the day: live life