public
Last active

IgnitedAsyncTask sample

  • Download Gist
gistfile1.java
Java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
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);
}
}
 
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.