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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:30:03+00:00 2026-05-27T16:30:03+00:00

Hello i did my notification of download file from web. Code below. I want

  • 0

Hello i did my notification of download file from web. Code below. I want handle click action on notification, close him and stop AsyncTask job. At current time i have incomprehensible to me actions. Like, when i click on notification its closed him but open again when call publishProgress method of AsyncTask. How i handle click on notification? May be i can do it differently than has? I put button in xml layout and setOnClickListener for call cancel(boolean) method but later learned that it impossible.

public class DownloadFileNotification extends AsyncTask<String, Integer, String> {

public DownloadVkVideoFiles(Context c, String title) {
  //constructor
}

public void createNotification() {
    //create notification
    notificationManager = (NotificationManager) context
            .getSystemService(context.NOTIFICATION_SERVICE);
    Intent notificationIntent = new Intent();

    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
            notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT);
    RemoteViews contentView = new RemoteViews(context.getPackageName(),
            R.layout.download_notification);

    // TODO change to shows title
    tickerText = context.getResources().getText(R.string.downloadTitle);
    icon = android.R.drawable.stat_sys_download;
    time = System.currentTimeMillis();

    notification = new Notification(icon, tickerText, time);
    notification.flags |= Notification.FLAG_ONGOING_EVENT;
    notification.flags |= Notification.FLAG_AUTO_CANCEL;

    contentView.setImageViewResource(R.id.downloadImage,
            R.drawable.download);
    contentView.setTextColor(R.id.title, notification_text_color);
    contentView.setFloat(R.id.title, "setTextSize",
            notification_text_size - 3);
    contentView.setTextViewText(R.id.title, title);
    contentView.setProgressBar(R.id.progressBar, 100, 0, false);

    notification.contentIntent = pendingIntent;
    notification.contentView = contentView;
    notificationManager.notify(HELLO_ID, notification);
}

@Override
protected void onPreExecute() {
    // execute the status bar notification
    createNotification();
    super.onPreExecute();
}

@Override
protected String doInBackground(String... params) {
    //download file
}

@Override
public void onProgressUpdate(Integer... progress) {
    //update progress bar notification
}

@Override
protected void onPostExecute(String result) {
    super.onPostExecute(result);
  // result processing 
}

@Override
protected void onCancelled() {
    super.onCancelled();
}

}
  • 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-27T16:30:04+00:00Added an answer on May 27, 2026 at 4:30 pm

    I would imagine something like a broadcast receiver or maybe even an activity or a service being designed to receive the intent fired by the notification click. This entity in turn might be used to cancel the task.

    Just call the cancel(true) method on the running Async object.

    //In your broadcast receiver/ activity / service
    sometask.cancel(true);
    .
    .
    .
    //Inside doInBackground()
    {
        while(!isCancled())
        {
            //continue task
        }
    }
    

    I hope it helps..

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

Sidebar

Related Questions

Hello I want to know if in the appengine env the things I did
Hello I did a mistake by setting UTF8 on a website that was on
Hello I asked this question to superuser but I did not get a good
Compare String.Format(Hello {0}, World); with Hello {0}.Format(World); Why did the .Net designers choose a
Hello i have tableview with many objects in it. If i want to add
Hello I am fairly new to Scala. I want to learn Scala because: To
When I did the practice below to erase my pointer member and assign new
Hello I have the following php code here: $username = trim(mysql_real_escape_string($username)); $password = md5(trim(mysql_real_escape_string($password)));
Hello i need to use writerreaderlock in my method. I want to know how
Hello I want a button to hide until my last image view has been

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.