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

  • SEARCH
  • Home
  • 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 8115463
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T03:29:23+00:00 2026-06-06T03:29:23+00:00

i have a problem with below’s code, onProgressUpdate is not running … however the

  • 0

i have a problem with below’s code, onProgressUpdate is not running … however the onPreExecute, doInBackground and onPostExecute is execute accordingly. or do i need a return in doInBackground? please advice me what is missed.
i used to deleted

notification.contentView.setProgressBar(R.id.pbStatus, 100, progress, false);
notificationManager = (NotificationManager) getApplicationContext().getSystemService(getApplicationContext().NOTIFICATION_SERVICE);
notificationManager.notify(42, notification);

in onCreate, then the notification didn’t appear at all. below is the full code :

package com.android.MaxApps;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.net.URLConnection;

import android.app.Activity;
import android.app.Dialog;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.widget.ProgressBar;
import android.widget.RemoteViews;
import android.widget.Toast;

public class StaffChoice extends Activity { 
    ProgressBar progressBar;
    private int progress;

    Intent MyI;
    PendingIntent MyPI;
    NotificationManager MyNM;
    Notification notification;
NotificationManager notificationManager;

@Override
protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.staffchoices);       

    MyI = new Intent(getApplicationContext(), MaxAppsAct.class);
    MyPI = PendingIntent.getActivity(getApplicationContext(), 0, MyI, 0);
    MyNM = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);

    Intent intent = new Intent(getApplicationContext(), MaxAppsAct.class);
    final PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent, 0);

    notification = new Notification(R.drawable.logo, "Downloading...", System.currentTimeMillis());
    notification.flags = notification.flags | Notification.FLAG_ONGOING_EVENT;
    notification.contentView = new RemoteViews(getApplicationContext().getPackageName(), R.layout.staffchoices);
    notification.contentIntent = pendingIntent;
    notification.contentView.setImageViewResource(R.id.imgIcon, R.drawable.save);
    notification.contentView.setTextViewText(R.id.tvText, "Downloading...");
    notification.contentView.setProgressBar(R.id.pbStatus, 100, progress, false);
    notificationManager = (NotificationManager) getApplicationContext().getSystemService(getApplicationContext().NOTIFICATION_SERVICE);
    notificationManager.notify(42, notification);

    String url = "http://www.domainURL.com/3d.png"; 
    new DownloadFileAsync().execute(url);
    }

public class DownloadFileAsync extends AsyncTask<String, String, String> {
    @Override
    protected void onPreExecute(){
        super.onPreExecute();
        }

    @Override
    protected String doInBackground(String... aurl) {
        int count;
        try {
            URL url = new URL(aurl[0]);
            URLConnection conexion = url.openConnection();
            conexion.connect();

            int lenghtOfFile = conexion.getContentLength();
            Log.d("ANDRO_ASYNC", "Lenght of file: " + lenghtOfFile);

            File folder = new File(Environment.getExternalStorageDirectory() + "/MaxApps");
            boolean success = false;
            if (!folder.exists()) {
                success = folder.mkdirs();
            }
            if (!success) {
            } else {
            }

            InputStream input = new BufferedInputStream(url.openStream());
            OutputStream output = new FileOutputStream("/sdcard/MaxApps/3d.png");

            byte data[] = new byte[1024];

            long total = 0;

            while ((count = input.read(data)) != -1) {
            total += count;
            publishProgress(""+(int)((total*100)/lenghtOfFile));
            output.write(data, 0, count);
            }

            output.flush();
            output.close();
            input.close();
            } catch (Exception e) {}

        return null;
    }

    protected void onProgressUpdate(Integer... progress) {          
        notification.contentView.setProgressBar(R.id.pbStatus, 100, progress[0], false);
        notificationManager.notify(42, notification);
        }

    @Override
    protected void onPostExecute(String unused) {           
        notificationManager.cancel(42);

        Notification MyN = new Notification(); MyN.icon = R.drawable.logo1;
        MyN.tickerText = "Download Complete"; 
        MyN.number = 1; 
        MyN.setLatestEventInfo (getApplicationContext(), "Application Title", "Application Description", MyPI); 

        MyNM.notify(1, MyN);
    }
}

}

  • 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-06-06T03:29:26+00:00Added an answer on June 6, 2026 at 3:29 am

    You declare your DownloadFileAsync class to publish progress updates as Strings:

    public class DownloadFileAsync extends AsyncTask<String, String, String>
    

    Yet you define onProgressUpdate() to take Integers:

    protected void onProgressUpdate(Integer... progress) {
    

    As such, it isn’t the onProgressUpdate() that AsyncTask uses. Assuming you want to use Strings, it should become

    @Override
    protected void onProgressUpdate(String... progress) {
    

    My guess is that you actually want to declare your class as:

    public class DownloadFileAsync extends AsyncTask<String, Integer, Void>
    

    In which case you can leave your onProgressUpdate() unchanged other than adding @Override. onPostExecute() would become

    @Override
    protected void onPostExecute(Void unused) {
    

    Which is clearer than (String unused), since it’s not used.

    General advice:

    1. @Override is your friend, as it helps catch this type of error.
    2. Be sure to read the documentation for AsyncTask, as you seem a little confused about its usage. That page explains these issues well.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem with the below code. It is not clear how I
I have a problem with this code: (The error is below the code) public
I have a problem when trying to execute this update statement (below) using C#
I have explained the problem below this code <div id='content'> <div id='help'> blah blah
UPDATE: I have realized the problem below is not possible to answer in its
I have the same problem as below: ASP.NET MVC 3 ValidateRequest(false) not working with
I have problem, the code below works fine, it creates a new Listbox control
I have problem in below code with idTCPClient for reading buffer from a telnet
I have problem with session and query execution,please see code below. class A implements
I have problem with session and query execution, please see code below. class A

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.