Notification shows after android app is force closed

后端 未结 4 2008
[愿得一人]
[愿得一人] 2020-12-21 15:13

I have googled this non stop today and could not find anything. My scenario is the following:

I have an Android app that auto replies to incoming messages. I have

相关标签:
4条回答
  • 2020-12-21 15:30

    If your notifications are handled by a service and target API is 14 or higher then you have an opportunity to cancel notifications in overriden "void onTaskRemoved(Intent rootIntent)" method.

    0 讨论(0)
  • 2020-12-21 15:40

    Have you try .setAutoCancel(true) in your notification and in your manifest add android:launchMode="singleTask" , android;clearTaskOnLauch="true" in the activity xml

    your notification icon should clear the moment you press it on the notification bar.

    0 讨论(0)
  • 2020-12-21 15:41

    As far as i can tell you are creating a new NotificationManager object to create the notification and a different notificationManager object to cancel the notifications. You should be using the same object. The way you are doing it, you are not firing any notification with the object in the notifDestroy(), hence probably it doesnt clear the notification for you.

    0 讨论(0)
  • 2020-12-21 15:48

    The method that I used to kill the processes when I swipe apps from the recents is: in the first activity of the app, in the method OnDestroy I write that "the process have to kill". In this way I call the OnDestroy method of the process and so the process really kills himself and the notification is removed. Specifically, in the first Activity:

        @Override
    public void onDestroy() {
      super.onDestroy();
    
      Intent intent = new Intent();
      intent.setAction(Service.MY_ACTION_FROMACTIVITY);
      intent.putExtra(Service.CMD, Service.CMD_STOP);
      sendBroadcast(intent);
    
    }
    

    So the following operations are:

    @Override
    public void onDestroy() {
        // TODO Auto-generated method stub
        barNotification.cancel(NOTIFICATION);
    
        sensorManager.unregisterListener(this);
    
        this.unregisterReceiver(myServiceReceiver);
        super.onDestroy();
    }
    

    I hope that I can help you.

    0 讨论(0)
提交回复
热议问题