Asynchronous startup progress dialog does not disappear

Hi I am downloading Tweets from a user account to show it in a list. Now I want users to know what is happening while they wait. I implemented Async Task, but for some reason onPostExcecute is never called. Therefore, the dialogue is never deleted.

Can someone give me a hint. What am I doing wrong?

I can publish my TweetAdapterClass if necessary

This is my AsyncClass

public class ProgressTask extends AsyncTask<Void, Void, Void> {


    @Override
    protected void onPreExecute() {
        dialog.setTitle("Even geduld...");
        dialog.setMessage("De tweets worden ingeladen...");
        dialog.show();
    }

    protected void onPostExecute() {
        try {
            if (dialog.isShowing()) {
                adaptor = new TweetListAdaptor(MainActivity.this, R.layout.tweetitem, loadTweets());
                setListAdapter(adaptor);
                dialog.dismiss();
            }
        } catch (Exception e) {
        }
    }

    @Override
    protected Void doInBackground(Void... arg0) {

        return null;

    }
}

LoadTweets looks like this:

private ArrayList<Tweets> loadTweets() {
    ArrayList<Tweets> tweets = new ArrayList<Tweets>();
    try {
        HttpClient hc = new DefaultHttpClient();
        HttpGet get = new HttpGet(
                "http://search.twitter.com/search.json?q=JobXXL_be&rpp=10");
        // HttpGet get = new
        // HttpGet("http://search.twitter.com/search.json?q=Stijn_messiaen&rp=10");

        HttpResponse rp = hc.execute(get);
        if (rp.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
            String result = EntityUtils.toString(rp.getEntity());
            JSONObject root = new JSONObject(result);
            JSONArray sessions = root.getJSONArray("results");
            for (int i = 0; i < sessions.length(); i++) {
                JSONObject session = sessions.getJSONObject(i);
                Tweets tweet = new Tweets();
                tweet.setTweet(session.getString("text"));
                tweet.setUser(session.getString("from_user"));
                // datum vertalen
                String date = session.getString("created_at").substring(5,
                        16);
                String[] arrDate = date.split(" ");
                int id = this.getResources().getIdentifier(
                        arrDate[1].toString(), "string",
                        this.getPackageName());
                String maand = getResources().getString(id);
                date = arrDate[0].toString() + " " + maand + " "
                        + arrDate[2].toString();

                tweet.setDate(date);
                tweets.add(tweet);
            }
        }
    } catch (Exception e) {
        Log.e("TwitterFeedActivity", "Error loading JSON", e);
    }
    return tweets;
}

EDIT: I added LoadTweets () to mine doInBackgroundMethodand solved my problems!

+3
source share
5 answers

ProgressDialog dialog , AsyncTask, dialog.show dialog.dismiss AsyncTask.

0

onCreateDialog(int id) ProgressDialog. AsyncTask:

MainActivity.this.showDialog(PROGRESS_DIALOG_ID);

:

MainActivity.this.dismissDialog(PROGRESS_DIALOG_ID);

. , , .

0

onPostExecute() Void. , :

protected void onPostExecute(Void result)

.

0

, , , onPostExecute ... - protected Void onPostExecute(Void... arg0)

, , Log.d( " ", " " ); , ...

u ...

0

Hmm, two things come here.

1) Why is your onPostExecute not overridden, like onPreExecute and doInBackground?

2) Why doInBackground after executing onPost? Usually order

onPreExecute doInBackground onPostExecute

0
source

All Articles