Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6945043
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:23:06+00:00 2026-05-27T13:23:06+00:00

In my app, every 60 seconds I get updates from a website. I get

  • 0

In my app, every 60 seconds I get updates from a website. I get this updates in background using a AsyncTask. Here is my code :

update = new Timer();
        update.scheduleAtFixedRate(new TimerTask() {
            @Override
            public void run() {
                runOnUiThread(new Runnable() {
                    public void run() {
                        updateItems();
                    }
                });
            }

        }, 30000, 60000);

where updateItems() method is :

public void updateItems() {
        System.out.println("Every 60 sec getItems");
        new DownloadTask().execute();
    }

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

        protected void onPostExecute(Void... args) {
            System.out.println("Download finished");
        }

        protected Void doInBackground(Void... args) {

            try {
                UpdateItems();
            } catch (Exception e1) {
                e1.printStackTrace();
            }

            return null;
        }
    }

In UpdateItems() I save all the updated images on SDcard. The problem is the onPostExecute() is not called after doInBackground() because I don’t get the message “Download finished”. On this method I want to update the ViewFlipper that is flipping and like this it is changed at second call of updateitems(). Have anyone any idea why I have this problem?

EDIT:

public void UpdateItems() throws Exception {

        String t = myPrefs.getString(TIME + idPlaylist, "time");
        String d = myPrefs.getString(DATE + idPlaylist, "date");
        String data_download = myPrefs.getString(DATA_DOWNLOAD + idPlaylist,
                "00000000");

        try {
            HttpClient httpclient = new DefaultHttpClient();

            String link = "some link where I send the last download date";
            System.out.println("trimit " + link);
            HttpPost httppost = new HttpPost(link);
            try {

                HttpResponse response = httpclient.execute(httppost);

                /* Checking response */
                if (response != null) {
                    String responseBody = EntityUtils.toString(response
                            .getEntity());
                    System.out
                            .println("Rezultat de la server :" + responseBody);

                    String jsonString = responseBody.toString();
                    JSONObject jsonObject = new JSONObject(jsonString);

                    String status = jsonObject.getString("status");
                    System.out.println("Status " + status);

                    if (status == "true") {
                        System.out.println("get updates");
                        GetItems();

                        updated = true;
                        dataupdate = new String[jArray.length()];
                        data = new String[jArray.length()];
                        time = new String[jArray.length()];
                        for (int i = 0; i < jArray.length(); i++) {
                            System.out
                                    .println("last update : " + lastupdate[i]);

                            String[] separated = lastupdate[i].split(" ");
                            data[i] = separated[0];
                            time[i] = separated[1];

                            dataupdate[i] = lastupdate[i].replace("-", "");
                            dataupdate[i] = dataupdate[i].replace(":", "");
                            dataupdate[i] = dataupdate[i].replace(" ", "");

                            System.out.println("data ultimului download "
                                    + data_download + "\ndata update "
                                    + dataupdate[i]);

                            if (Long.valueOf(dataupdate[i]) > Long
                                    .valueOf(data_download)) {
                                System.out.println("image update");
                                saveImageToSDcard(url[i], i);
                                if (target[i].endsWith(".mp4")) {
                                    System.out.println("video de downloadat");
                                    try {
                                        saveVideoToSDcard(target[i], i);
                                        path[i] = Environment
                                                .getExternalStorageDirectory()
                                                + "/BouyguesVideos"
                                                + idPlaylist
                                                + "/" + "Video" + idPhotos[i];
                                    } catch (SocketException e) {
                                        System.out.println("Socket timeout");
                                        e.printStackTrace();
                                    } catch (Exception e) {
                                        e.printStackTrace();
                                    }
                                } else
                                    path[i] = target[i];
                            } else
                                System.out.println("image not update");
                        }

                        String actual = dataupdate[0];
                        int indexmax = 0;
                        for (int k = 1; k < jArray.length(); k++) {
                            if (Long.valueOf(dataupdate[k]) > Long
                                    .valueOf(actual)) {
                                actual = dataupdate[k];
                                indexmax = k;
                            }
                        }

                        System.out.println("max " + actual);

                        prefsEditor
                                .putString(DATE + idPlaylist, data[indexmax]);
                        prefsEditor
                                .putString(TIME + idPlaylist, time[indexmax]);
                        prefsEditor.putString(DATA_DOWNLOAD + idPlaylist,
                                actual);
                        prefsEditor.commit();

                        File f = new File(
                                Environment.getExternalStorageDirectory()
                                        + "/BouyguesImages" + idPlaylist + "/");
                        File[] files = f.listFiles();

                        System.out
                                .println("pe card avem " + files.length
                                        + " fisiere" + " iar online "
                                        + jArray.length());

                        if (files.length != jArray.length()) {
                            System.out.println("imagini adaugate sau sterse");

                            for (int k = 0; k < jArray.length(); k++) {
                                System.out.println("imagini pe site "
                                        + idPhotos[k] + namePhotos[k]);
                                ok = false;
                                for (int i = 0; i < files.length; i++) {
                                    System.out.println("comparam "
                                            + files[i].getName() + " cu "
                                            + idPhotos[k] + namePhotos[k]);
                                    if (files[i].getName().equals(
                                            idPhotos[k] + namePhotos[k])) {
                                        System.out.println("exista");
                                        i = files.length;
                                        ok = true;
                                    }
                                }

                                if (ok == false) {
                                    System.out
                                            .println("not exist-must save now");
                                    try {
                                        saveImageToSDcard(url[k], k);
                                    } catch (IOException e1) {
                                        e1.printStackTrace();
                                    }

                                    if (target[k].endsWith(".mp4")) {
                                        try {
                                            saveVideoToSDcard(target[k], k);
                                            path[k] = Environment
                                                    .getExternalStorageDirectory()
                                                    + "/BouyguesVideos"
                                                    + idPlaylist
                                                    + "/"
                                                    + "Video" + idPhotos[k];

                                        } catch (Exception e) {
                                            e.printStackTrace();
                                        }
                                    }
                                }
                            }

                        }

                        for (int k = 0; k < files.length; k++) {
                            System.out.println("imagini deja salvate "
                                    + files[k].getName());
                            ok = false;
                            for (int i = 0; i < jArray.length(); i++) {
                                System.out.println("comparam "
                                        + files[k].getName() + " cu "
                                        + idPhotos[i] + namePhotos[i]);
                                if (files[k].getName().equals(
                                        idPhotos[i] + namePhotos[i])) {
                                    System.out.println("exista");
                                    i = jArray.length();
                                    ok = true;
                                }
                            }

                            if (ok == false) {
                                System.out.println("delete- not exist more");
                                files[k].delete();
                            }
                        }

                    } else {
                        System.out.println("no updates");
                    }
                }
            } catch (ClientProtocolException e) {

            } catch (IOException e) {
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T13:23:06+00:00Added an answer on May 27, 2026 at 1:23 pm

    You should add the @Override over the onPostExecute and doInBackground (to be sure they’re both correctly overriden).

    I think it will have something to do with this.

    UPDATE:

    Try this:

    public class DownloadTask extends AsyncTask<Void, Void, Object> {
    
    @Override
    protected Object doInBackground(Void... params) {
        ...
        }
    
    @Override
    protected void onPostExecute(Object object) {
        ....
        }
    

    More details here: Can't Override onPostExecute() method in AsyncTask Class or get it to trigger

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm successfully using Paypal Express Checkout in a marketplace web app passing for every
In my app, I need every new record to be added to the index
My code is basically allocation free, however the GC runs every 30 seconds or
I am using node.js to query a MySQL database table every 10 seconds. Using
I'm supposed to update the listener every 5 seconds. But it doesn't. What could
My Rails app needs to retrieve an updated count from the server every minute.
I have an application that start System.Threading.Timer, then this timer every 5 seconds read
Every time I try to post to twitter in my rails app, the first
My wpf app is eating memory every time the ItemsSource of a TreeView is
every iPhone and iPod Touch has got the Apple Addresses App ... when you

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.