Skip to content

Instantly share code, notes, and snippets.

@mttkay
Created November 25, 2011 13:39
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mttkay/1393552 to your computer and use it in GitHub Desktop.
Save mttkay/1393552 to your computer and use it in GitHub Desktop.
IgnitedAsyncTask sample
import com.github.ignition.core.tasks.IgnitedAsyncTask;
public class IgnitedAsyncTaskActivity extends Activity {
private SampleTask task;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
task = (SampleTask) getLastNonConfigurationInstance();
if (task == null) {
task = new SampleTask();
}
task.connect(this);
if (task.isRunning()) {
// show progress dialog or something
} else if (task.isPending()) {
task.execute();
}
}
@Override
public Object onRetainNonConfigurationInstance() {
return task;
}
@Override
protected void onDestroy() {
super.onDestroy();
task.disconnect();
}
public void updateViews(Void result) {
// ...
}
private static class SampleTask extends
IgnitedAsyncTask<IgnitedAsyncTaskActivity, Void, Void, Void> {
@Override
protected void onStart(IgnitedAsyncTaskActivity context) {
}
@Override
protected Void run(Void... params) throws Exception {
System.out.println("Working...");
return null;
}
@Override
protected void onSuccess(IgnitedAsyncTaskActivity context, Void result) {
context.updateViews(result);
}
@Override
protected void onError(IgnitedAsyncTaskActivity context, Exception error) {
super.onError(context, error);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment