Как правильно обрабатывать поворот экрана с помощью ViewPager и вложенных фрагментов?

Переместите эти две строки:

TextView txt = (TextView) findViewById(R.id.output);
txt.setText("Executed");

из вашего метода doInBackground AsyncTask и поместите их в метод onPostExecute. Ваш AsyncTask должен выглядеть примерно так:

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

    @Override
    protected String doInBackground(String... params) {
        try {
            Thread.sleep(5000); // no need for a loop
        } catch (InterruptedException e) {
            Log.e("LongOperation", "Interrupted", e);
            return "Interrupted";
        }
        return "Executed";
    }      

    @Override
    protected void onPostExecute(String result) {               
        TextView txt = (TextView) findViewById(R.id.output);
        txt.setText(result);
    }
}
30
задан Benoit Duffez 31 December 2013 в 09:22
поделиться