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 7560233
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T12:50:50+00:00 2026-05-30T12:50:50+00:00

I am uploading a video file using an Async Task. To track the progress

  • 0

I am uploading a video file using an Async Task. To track the progress I have a notification running in the statusbar. The notification works and updates correctly, but it causes severe performance issues to the extent where the statusbar crashes and the phone needs to be restarted. My code as follows:

    private class UploadMedia extends AsyncTask<Void, Integer, String> {

    private int NOTIFICATION_ID = 1;
    private CharSequence _contentTitle;
    private final NotificationManager _notificationManager = (NotificationManager) getActivity()
            .getApplicationContext()
            .getSystemService(
                    getActivity().getApplicationContext().NOTIFICATION_SERVICE);
    Notification _notification;
    PendingIntent _pendingIntent;

    private long totalSize;
    private int _progress = 0;
    private InputStreamBody isb;
    private File uploadFile;

    protected void onPreExecute() {

        Intent intent = new Intent();
        _pendingIntent = PendingIntent.getActivity(getActivity(), 0,
                intent, 0);

        _contentTitle = "Uploader " + mediaTitle + " til Skoletube";
        CharSequence contentText = _progress + "% complete";

        _notification = new Notification(R.drawable.icon, _contentTitle,
                System.currentTimeMillis());
        _notification.flags = _notification.flags
                | Notification.FLAG_ONGOING_EVENT;
        _notification.contentIntent = _pendingIntent;
        _notification.setLatestEventInfo(getActivity(), _contentTitle,
                contentText, _pendingIntent);

        _notificationManager.notify(NOTIFICATION_ID, _notification);

        Toast.makeText(getActivity(), "Starter upload", Toast.LENGTH_SHORT)
                .show();

        try {
            uploadFile = new File(_mediaFile.getPath());

            // FileInputStream is = new FileInputStream(uploadFile);
            //
            // ByteArrayOutputStream bos = new ByteArrayOutputStream();
            // byte[] b = new byte[1024];
            // int bytesRead;
            // while ((bytesRead = is.read(b)) != -1) {
            // bos.write(b, 0, bytesRead);
            // }
            // byte[] data = bos.toByteArray();
            //
            // isb = new InputStreamBody(new ByteArrayInputStream(data),
            // uploadFile.getName());

        } catch (Exception ex) {
            Log.i(TAG,
                    "Pre execute - oh noes... D: "
                            + ex.getLocalizedMessage());
        }

    }

    @Override
    protected String doInBackground(Void... params) {
        String result = "";
        try {
            // Inititate connectionparts
            HttpClient client = new DefaultHttpClient();
            HttpPost postRequest = new HttpPost(
                    "http://www.skoletube.dk/beta/api_userupload.php");

            CustomMultipartEntity multipartE = new CustomMultipartEntity(
                    HttpMultipartMode.BROWSER_COMPATIBLE,
                    new ProgressListener() {

                        @Override
                        public void transferred(long num) {
                            publishProgress((int) ((num / (float) totalSize) * 100));

                        }
                    });

            // Add the post elements
            String timestamp = String
                    .valueOf(System.currentTimeMillis() / 1000);
            String mode = "xml";
            String hashSum = Utils.md5(ActiveUser.getPartner() + timestamp
                    + ActiveUser.getInstance().getToken()
                    + ActiveUser.getInstance().getSecret()
                    + ActiveUser.getInstance().getUserID()
                    + spnChannel.getSelectedItem().toString()
                    + mediaDescribtion + "KEYWORDLOL"
                    + spnPublic.getSelectedItem().toString() + mediaTitle
                    + ActiveUser.getSharedkey());

            multipartE.addPart("uid", new StringBody(ActiveUser
                    .getInstance().getUserID()));
            multipartE.addPart("token", new StringBody(ActiveUser
                    .getInstance().getToken()));
            multipartE.addPart("token_secret", new StringBody(ActiveUser
                    .getInstance().getSecret()));
            multipartE.addPart("partner",
                    new StringBody(ActiveUser.getPartner()));
            multipartE.addPart("timestamp",
                    new StringBody(timestamp.toString()));
            multipartE.addPart("key", new StringBody(hashSum));
            multipartE.addPart("video_title", new StringBody(mediaTitle));
            multipartE.addPart("video_desc", new StringBody(
                    mediaDescribtion));
            multipartE.addPart("video_keyword",
                    new StringBody("KEYWORDLOL"));
            multipartE.addPart("video_privacy", new StringBody(spnPublic
                    .getSelectedItem().toString()));
            multipartE.addPart("video_channel", new StringBody(spnChannel
                    .getSelectedItem().toString()));
            multipartE.addPart("videoupload", new FileBody(uploadFile));

            postRequest.setEntity(multipartE);

            totalSize = multipartE.getContentLength();


            HttpResponse loginResponse = client.execute(postRequest);
            HttpEntity theEnt = loginResponse.getEntity();
            result = EntityUtils.toString(theEnt);

            Log.i(TAG, "Result: " + result);

        } catch (Exception ex) {
            Log.i(TAG,
                    "Do in background - oh noes... D: "
                            + ex.getLocalizedMessage());

        }
        return result;
    }

    @Override
    protected void onProgressUpdate(Integer... progress) {
        if (_notification == null)
            return;
        _progress = progress[0];
        _contentTitle = "Uploader " + mediaTitle + " til Skoletube";
        CharSequence contentText = _progress + "% complete";
        _notification.setLatestEventInfo(getActivity(), _contentTitle,
                contentText, _pendingIntent);
        _notificationManager.notify(NOTIFICATION_ID, _notification);
    }

    @Override
    protected void onPostExecute(String result) {
        _notificationManager.cancel(NOTIFICATION_ID);
    }

}

I am testing this on a HTC Sensation. The problems occur the instant I press the notification bar, causing it to expand. The phone freezes and its touch and go whether I will actually get to the notification bar or the notification bar will crash. If i do get to the notification bar the performance issues persist, and closing the notification bar again is just as tricky as opening it.
What I’m thinking is maybe the sheer amount of notification updates sent could be causing the problem, but I am not sure.

Appreciate any ideas and suggestions.

  • 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-30T12:50:51+00:00Added an answer on May 30, 2026 at 12:50 pm

    Your suspicions are right.
    The following instruction

    publishProgress((int) ((num / (float) totalSize) * 100));
    

    will be called very frequently, at short intervals.

    What I would do in such situation is to store the pourcent avancement I want to display and send it only if it changed since the latest call.

    In the doInBackground method, you can declare a variable such as:

    int lastPourcent = 0;
    

    Then, in the transferred method:

    int currentPoucent = (int) ((num / (float) totalSize) * 100);
    if (currentPourcent > lastPourcent) {
        publishProgress(currentPourcent);
        lastPourcent = currentPourcent;
    }
    

    It will significantly reduce the number of call to the refresh method of the Notification.

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

Sidebar

Related Questions

I am using paperclip for uploading file ( video and images). Have used the
i have a web application for video uploading,In that i want to show the
In my web application (asp.net,c#) I am uploading video file in a page but
How to a create thumb image while uploading a video, am using the following
I am uploading a video file which is in .mov or .mp4. I want
I am using the following code for uploading videos $img1 = $_FILES['video']['name']; if (!empty($img1))
How can I upload a File (graphic, audio and video file) with Android using
in order to monitor the upload of large video files I'm using the progress
When I am uploading the video file to the server I sending the sample
I am uploading a stream to server.But my Input-stream contain a big video file.So

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.