AsyncTask doInBackground

时间:2014-04-11 20:54:49

标签: android android-asynctask

在我的应用程序中,我同时使用2个asyncTasks将2个单独的xmls读入字符串。 但是,有时当我运行应用程序时,我只得到白屏,然后它会在一段时间后回到桌面。主要是我做{} while(!read1 ||!read2)等待xmls读取。然后我进一步处理字符串。

这是我的asyncTask代码,另一个非常相似。

private class Read1 extends AsyncTask<String, Void, Void>{

        @Override
        protected Void doInBackground(String... read) {
            String text="";
            try {

                File sdcard = Environment.getExternalStorageDirectory();
                File file = new File(sdcard,read[0]);

                    BufferedReader br = new BufferedReader(new InputStreamReader(
                            new FileInputStream(file), "ISO-8859-2"),8192);
                    String line;   
                    while ((line = br.readLine()) != null) {

                                text+=line;

                                } br.close();}
                catch (IOException e) {
                    e.printStackTrace();
                }

            text1=text;
            read1=true;
            return null;
        }       
    }

实际上。大多数时候,我得到这个白色屏幕是当我关闭应用程序,然后在短时间内再次运行它。有什么想法吗?

1 个答案:

答案 0 :(得分:1)

不要在main中等待,而是在onPostExecute()中进一步处理字符串。

相关问题