Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ContinuousTask extends AsyncTask<String,String,String> {
- private Stack<Runnable> runnables = new Stack<>();
- private Runnable onFinish;
- @Override
- protected String doInBackground(String... params) {
- while(!runnables.isEmpty())
- {
- runnables.pop().run();
- }
- return null;
- }
- @Override
- protected void onPostExecute(String s) {
- super.onPostExecute(s);
- if(onFinish != null)
- onFinish.run();
- }
- public ContinuousTask then(Runnable runnable)
- {
- runnables.push(runnable);
- return this;
- }
- public ContinuousTask finish(Runnable runnable)
- {
- onFinish = runnable;
- return this;
- }
- }
- new ContinuousTask().then(new Runnable() {
- @Override
- public void run() {
- // codigo 1
- }
- }).then(new Runnable() {
- @Override
- public void run() {
- // codigo 2
- }
- }).then(new Runnable() {
- @Override
- public void run() {
- // codigo 3
- }
- }).finish(new Runnable() {
- @Override
- public void run() {
- // metodo final
- }
- }).runTasks();// se ejecuta los tasks
Add Comment
Please, Sign In to add comment