AsyncTask中的大阅读功能?

时间:2013-04-26 14:11:10

标签: java android asynchronous

我有一个很大的阅读功能,它减慢了app的速度。所以我听到了一些AsyncTasks。如何将此函数放入AsyncTask中,最好是在外部类中,例如Reading.java并在每次需要时从MainActivity.java

调用此函数

任何人都可以帮助我吗?

编辑:重要的是我需要给函数一个String作为参数

1 个答案:

答案 0 :(得分:0)

您可以定义一个AsyncTask,它接受一个String参数,如下所示:

public class LargeTask extends AsyncTask<String, Void, Void> {
     protected void doInBackground(String... strings) {
         String your_string = strings[0]; //Retrieve the first parameter
         //Your "big reading function" goes here
     }

     protected void onPostExecute(Void result) {
         //Do something when done
     }
 }

然后你可以像这样调用并运行它:

new LargeTask().execute(your_string_parameter);

可以找到有关AsyncTask的更多信息here