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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:43:19+00:00 2026-06-13T11:43:19+00:00

I have an activity that creates notifications using the following code: Notification notification =

  • 0

I have an activity that creates notifications using the following code:

Notification notification = new Notification(icon,
                        tickerText, 0);
                notification.flags |= Notification.FLAG_AUTO_CANCEL;
                Context context = getApplicationContext();
                CharSequence contentText = getString(R.string.subtitle);
                Intent notificationIntent = new Intent(getBaseContext(),
                        MainActivity.class);
                notificationIntent.putExtra("num", Integer.toString(i));
                Intent deleteIntent = new Intent(getBaseContext(),
                        DeleteActivity.class);
                deleteIntent.putExtra("num", Integer.toString(i));
                PendingIntent contentIntent = PendingIntent.getActivity(
                        getBaseContext(), ran, notificationIntent, 0);
                PendingIntent deletePendingIntent = PendingIntent
                        .getActivity(getBaseContext(), ran, deleteIntent, 0);
                notification.setLatestEventInfo(context, text, contentText,
                        contentIntent);
                notification.deleteIntent = deletePendingIntent;
                final int NOTIF_ID = ran;
                mNotificationManager.notify(NOTIF_ID, notification);

I keep a list of all the notifications from my app that are currently showing.

When the notification is clicked, it opens the MainActivity. I have some code in the onResume() to delete the notification from the list. This works fine.

When the notification is dismissed, it triggers DeleteActivity, which also deletes it from my list. This also works fine.

The problem is, if MainActivity is already open, and the notification is clicked, the onResume() doesn’t run again, and so the notification is gone, but it’s not deleted from the list of notifications that the app thinks are showing.

I’m wondering if there’s any way I can execute a particular piece of code (or even just restart the whole activity) when the intent is received. I know I could just set it to use DeleteActivity instead but I’d rather have it open the MainActivity.

  • 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-13T11:43:20+00:00Added an answer on June 13, 2026 at 11:43 am

    You can catch the notification click in your Activity by overiding onNewIntent. This is what I do in my App.

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

Sidebar

Related Questions

I currently have this code that creates 4 tabs using tabactivity: public class toknapp
I have an app that displays a splash screen. The splash screen activity creates
I have a program that creates a notification if the application is not running.
I currently have an activity model that handles a user activity notification system. An
I have an application that creates a notification with sound when a specific text
I have a notification set up in an activity. It creates the notification as
I have the following code which I am using for an android app: package
I have an Activity that should only get created once. That is, onCreate can
I have created an Activity that will behave like a popup menu is actually
I have created a custom workflow activity that copies attachments from a case to

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.