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 ?