Android Open Source - Android-Wizard-Framework Task Fragment






From Project

Back to project page Android-Wizard-Framework.

License

The source code is released under:

MIT License

If you think the Android project Android-Wizard-Framework listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.hps.wizard;
//from  ww w. j av a2  s .c  om
import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;

/**
 * This Fragment manages a single background task and retains itself across configuration changes.
 */
public class TaskFragment extends Fragment {

  private TaskCallback callback;
  private ValidationAsyncTask task;

  /**
   * Hold a reference to the parent Activity so we can report the task's current progress and results. The Android framework will pass us a reference to the
   * newly created Activity after each configuration change.
   */
  @Override
  public void onAttach(Activity activity) {
    super.onAttach(activity);
    callback = (TaskCallback) activity;
  }

  /**
   * This method will only be called once when the retained Fragment is first created.
   */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Retain this fragment across configuration changes.
    setRetainInstance(true);
  }

  /**
   * Executes the given {@link ValidationAsyncTask}.
   * 
   * @param validationTask
   *            The task to execute.
   */
  void execute(ValidationAsyncTask validationTask) {
    this.task = validationTask;
    task.setCallback(callback);
    Object noParameters = null;
    task.execute(noParameters);
  }

  /**
   * Set the callback to null so we don't accidentally leak the Activity instance.
   */
  @Override
  public void onDetach() {
    super.onDetach();
    callback = null;
  }
}




Java Source Code List

com.hps.wizard.AbstractWizardActivity.java
com.hps.wizard.StateFragment.java
com.hps.wizard.TaskCallback.java
com.hps.wizard.TaskFragment.java
com.hps.wizard.ValidationAsyncTask.java
com.hps.wizard.WizardActivity.java
com.hps.wizard.WizardDialog.java
com.hps.wizard.sample.activities.MainActivity.java
com.hps.wizard.sample.states.AreYouSure.java
com.hps.wizard.sample.states.BackgroundValidation.java
com.hps.wizard.sample.states.Choice.java
com.hps.wizard.sample.states.Instructions.java
com.hps.wizard.sample.states.MuppetShow.java
com.hps.wizard.sample.states.Results.java
com.hps.wizard.sample.states.SesameStreet.java
com.hps.wizard.sample.states.Seuss.java