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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:47:02+00:00 2026-06-11T19:47:02+00:00

I have a foreground service notification that when clicked should start an activity. This

  • 0

I have a foreground service notification that when clicked should start an activity. This activity is very short lived before it calls finish().

The first time the notification is clicked it works, the second time and thereafter I get the error:

    Sending contentIntent failed: android.app.PendingIntent$CanceledException

In my code when creating the foreground service notification, I’ve changed the randomActivity.class to another Activity class that does not call finish and it works perfectly on every click. From:

    Intent notificationIntent = new Intent(this, RandomActivity.class);

to:

    Intent notificationIntent = new Intent(this, HomeActivity.class);

Works fine…

I’ve used the standard notification code from the Android Developers website, as well as testing it using Notification builder. I get the same result regardless. It works perfectly unless the Activity calls finish();

Is this expected behaviour, a bug, or am I missing something?

I thank you in advance for you help and hopefully a solution!

Note: The notification code I use is completely standard, so I haven’t posted it. RandomActivity calls finish(); in onCreate, so there’s nothing unusual to see there either.

  • 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-11T19:47:03+00:00Added an answer on June 11, 2026 at 7:47 pm

    After trying everything I possibly could, I eventually found a solution. Posting in case anyone stumbles across this issue too.

    I had to match the int requestCode to the notification id. Why? Absolutely no idea… I can only assume it prevents the intent data from becoming null or reusing it?

        private static int ONGOING_NOTIFICATION_ID = 76;
    
        PendingIntent contentIntent = PendingIntent.getActivity(this,
        ONGOING_NOTIFICATION_ID, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    

    The same as the notification id to startForeground:

        this.startForeground(ONGOING_NOTIFICATION_ID, not);
    

    Hope this helps someone.

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

Sidebar

Related Questions

I have a service that work in foreground, and when the Main activity launch
I have a c++ process, I want that process should always remain on foreground,
I'm writing an app that has a foreground service, content provider, and a Activity
I have a service that create a notification when it is started. And then
I have a timer that start a notification when it ends. But I would
I have a foreground service that runs as long as I have a Wifi
I have made a foreground service that work with a runnable object that is
I have an android app which runs a foreground service and while that service
Condition: I have a client activity X of a remote service (with AIDL) that
I have UserControls containing other controls. I want that if I set a Foreground

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.