小编Inv*_*ame的帖子

RxJava2就像Android中的AsyncTask一样

嗨,我刚开始学习使用RxJava2进行反应式编程.如何创建在后台线程中运行的任务,然后使用RxJava2在主线程上完成.

在Android中我们使用AsyncTask的示例就像下面的示例

private class MyTask extends AsyncTask<String, Integer, Boolean>
{
    @Override
    protected Boolean doInBackground(String... paths)
    {
        for (int index = 0; index < paths.length; index++)
        {
            boolean result = copyFileToExternal(paths[index]);

            if (result == true)
            {
                // update UI
                publishProgress(index);
            }
            else
            {
                // stop the background process
                return false;
            }
        }

        return true;
    }

    @Override
    protected void onProgressUpdate(Integer... values)
    {
        super.onProgressUpdate(values);
        int count = values[0];
        // this will update my textview to show the number of files copied
        myTextView.setText("Total files: …
Run Code Online (Sandbox Code Playgroud)

android reactive-programming rx-java rx-java2

6
推荐指数
1
解决办法
3652
查看次数

标签 统计

android ×1

reactive-programming ×1

rx-java ×1

rx-java2 ×1