Created
November 25, 2011 13:39
-
-
Save mttkay/1393552 to your computer and use it in GitHub Desktop.
IgnitedAsyncTask sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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