Android Open Source - AndroidTasks Task With Ui Thread Access Activity






From Project

Back to project page AndroidTasks.

License

The source code is released under:

Apache License

If you think the Android project AndroidTasks 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.beyondar.android.util.task.example;
/*  ww w  .ja va  2 s  .  c o m*/
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import com.beyondar.android.util.annotation.OnUiThread;
import com.beyondar.android.util.task.BaseTask;
import com.beyondar.android.util.task.TaskExecutor;
import com.beyondar.android.util.task.TaskResult;


public class TaskWithUiThreadAccessActivity extends Activity {

    private Button buttonStart;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        buttonStart = (Button) findViewById(R.id.buttonStart);

        buttonStart.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                CustomTask customTask = new CustomTask();
                TaskExecutor.getInstance().addTask(customTask);
            }
        });
    }

    private class CustomTask extends BaseTask{

        public CustomTask() {
            super();
        }

        @Override
        @OnUiThread
        public void onFinish() {
            Toast.makeText(TaskWithUiThreadAccessActivity.this, "Task finished", Toast.LENGTH_SHORT).show();
        }

        @Override
        @OnUiThread
        public TaskResult runTask() {
            Toast.makeText(TaskWithUiThreadAccessActivity.this, "Doing something", Toast.LENGTH_SHORT).show();
            return null;
        }
    }
}




Java Source Code List

com.beyondar.android.util.annotation.AnnotationsUtils.java
com.beyondar.android.util.annotation.OnUiThread.java
com.beyondar.android.util.task.BaseTask.java
com.beyondar.android.util.task.BaseTimerTask.java
com.beyondar.android.util.task.OnFinishTaskListener.java
com.beyondar.android.util.task.OnFinishTask.java
com.beyondar.android.util.task.OnThreadFromPoolStop.java
com.beyondar.android.util.task.PoolThreads.java
com.beyondar.android.util.task.RunnableTask.java
com.beyondar.android.util.task.SimpleTask.java
com.beyondar.android.util.task.TaskExecutor.java
com.beyondar.android.util.task.TaskResult.java
com.beyondar.android.util.task.Task.java
com.beyondar.android.util.task.ThreadFromPool.java
com.beyondar.android.util.task.Version.java
com.beyondar.android.util.task.example.MainActivity.java
com.beyondar.android.util.task.example.TaskWithDependenciesActivity.java
com.beyondar.android.util.task.example.TaskWithUiThreadAccessActivity.java