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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:41:26+00:00 2026-06-17T08:41:26+00:00

I manage an ONGOING notification from my application (not from a service). When I

  • 0

I manage an ONGOING notification from my application (not from a service).

When I kill application from task manager with “End” button, notification disappear.

When I remove application from multitask pannel, application is killed but notification remains.

My questions are:

  • How to catch this event to clear notification?
  • What happens when application is removed from multitask pannel? Application is destroyed but process staying alive? Is it normal?

As an update:

All my activities extends MyActivity class (which extends Activity) with methods:

@Override protected void onCreate(Bundle state) {
    super.onCreate(state);
    ((MyApplication) getApplication()).onActivityCreate(this, state);
}

@Override protected void onDestroy() {
    super.onDestroy();
    ((MyApplication) getApplication()).onActivityDestroy(this);
}

And my application extends MyApplication class (which extends Application) with methods:

private List<Activity> activities = new ArrayList<Activity>();

protected final void onActivityCreate(Activity activity, Bundle state) {
    if(activities.isEmpty() && state == null) {
        onStart();
    }
    activities.add(activity);
}

protected final void onActivityDestroy(Activity activity) {
    activities.remove(activity);
    if(activities.isEmpty() && activity.isFinishing()) {
        onExit();
    }
}

protected void onStart() {
    // some code
}

protected void onExit() {
    // some code
    notificationManager.cancel(NOTIFICATION_ID);
}

activities is a list of all running activities

It’s not simplest mechanism but I need it

Should I use a service instead?


As a new update:

In my onExit() method, if I Log debug message to know what happens like this:

public void onExit() {
    for(int i = 0; i < 100; i++) {
        Log.d(TAG, "onExit");
    }
}

a small amount of log appears once on two, not all (ex: 13/100)

So, I understand that remove application from multitask pannel force to kill application without waiting close methods end to finish properly… But why not process ?!

How can I force to terminate properly ?

  • 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-17T08:41:27+00:00Added an answer on June 17, 2026 at 8:41 am

    Killing Notifications when main app has been killed.

    Since your notification and your app are handled in different threads killing your app via MultitaskManager won’t kill your notification. As you already correctly investigated killing your app won’t even necesarrily result in an onExit() callback.

    So what is the solutions?

    You could start a service from your activity. A specialty services have: they restart themselves automatically if app-process have been killed for some reason. So you could reuse the automatic restart by killing the notification on restart.

    Step 1 create a service that kills
    Simple one. It just kills a notification on create and has his special Binder.

    public class KillNotificationsService extends Service {
    
        public class KillBinder extends Binder {
            public final Service service;
    
            public KillBinder(Service service) {
                this.service = service;
            }
    
        }
    
        public static int NOTIFICATION_ID = 666;
        private NotificationManager mNM;
        private final IBinder mBinder = new KillBinder(this);
    
        @Override
        public IBinder onBind(Intent intent) {
                return mBinder;
        }
        @Override
        public int onStartCommand(Intent intent, int flags, int startId) {
                return Service.START_STICKY;
        }
        @Override
        public void onCreate() {
                mNM = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
                mNM.cancel(NOTIFICATION_ID);
        }
    }
    

    Step2: Add it to your manifest:
    Add it somewhere inbetween your <application> tags.

    <service android:name="KillNotificationsService"></service>
    

    Step3: Always create the Service before fireing the notification, and use the static notificationid.

    ServiceConnection mConnection = new ServiceConnection() {
        public void onServiceConnected(ComponentName className,
                IBinder binder) {
            ((KillBinder) binder).service.startService(new Intent(
                    MainActivity.this, KillNotificationsService.class));
            Notification notification = new Notification(
                    R.drawable.ic_launcher, "Text",
                    System.currentTimeMillis());
            Intent notificationIntent = new Intent(MainActivity.this,
                    Place.class);
            PendingIntent contentIntent = PendingIntent.getActivity(
                    MainActivity.this, 0, notificationIntent, 0);
            notification.setLatestEventInfo(getApplicationContext(),
                    "Text", "Text", contentIntent);
            NotificationManager mNM = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
            mNM.notify(KillNotificationsService.NOTIFICATION_ID,
                    notification);
        }
    
        public void onServiceDisconnected(ComponentName className) {
        }
    
    };
    bindService(new Intent(MainActivity.this,
            KillNotificationsService.class), mConnection,
            Context.BIND_AUTO_CREATE);
    

    It might take a little time until service is restarted (1-5 sec), but it will eventually start and kill the notification.

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

Sidebar

Related Questions

I manage to identify duplicate records from two different databases: select * from taskperformance
I manage a rather large application (50k+ lines of code) by myself, and it
I'm designing a concurrent Java application that reads data from various medical devices available
./manage.py compilemessages throws this error: sh: msgfmt: command not found I am running Mac
I manage to retrieve Json content from the URL: http://twitter.com/statuses/public_timeline.json Which provide just tweets.
I manage a very large web/database application (currently about 80 ASPX pages). This is
I am running into a strange issue with notification icons in my application. My
python manage.py flush removes data from the entire project. I would like to be
I manage to display a webview with the content that being derived from string,
I manage the real 404 errors in this way: application = webapp.WSGIApplication([ ('/', MainPage),

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.