应用程序关闭时运行功能 - Android

问题描述

我想不断地向用户显示一个持续的通知,当用户在“任务管理器”中杀死应用程序时,该通知不会消失。问题是,当发生这种情况时(用户在“任务管理器”中杀死应用程序),@R_404_5737@的通知消失了。作为解决方案,我想在应用程序被用户或 android 本身杀死时重新发送通知。我尝试使用与 PACKAGE_RESTARTED 操作连接的 broadcastReciever 来处理此问题(如此 post 中建议的那样),但它不起作用(未调用 sysout)。有什么解决办法吗?

我的广播接收器:

package com.appstiq.Flutter_app;

public class AutoConnection extends android.content.broadcastReceiver {

    @Override
    public void onReceive(Context context,Intent intent) {
        /*This function should be called when the app is killed
          so that I can resend the notification */ 
        System.out.println("It works!");
    }
}

我的 AndroidManifest.xml 的一部分:

<receiver android:name="com.appstiq.Flutter_app.AutoConnection">
      <intent-filter>
            <action android:name="android.intent.action.PACKAGE_RESTARTED"/>
            <data android:scheme="package" android:path="com.appstiq.Flutter_app"/>
      </intent-filter>
</receiver>

我期待有用的答案:D

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)