如果我关闭最近的应用程序,BroadcastReceiver 不起作用 [英] BroadcastReceiver Doesnt work if I close Recent Apps

查看:33
本文介绍了如果我关闭最近的应用程序,BroadcastReceiver 不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作一个应用程序,如果触发特定事物,将调用该应用程序.在我的应用程序中,这件事是短信.当收到新短信时,我会阅读其内容并查找特定内容,如果出现,则会发出警报.

I am Trying to make an app which app will be called if a particular thing triggered. In my App this thing is sms.. When a new Sms Receiving I Read its contents and i Look for a Specific Content If it presents an alarm will goes on.

如果应用程序打开,它就可以正常工作.接收器触发良好......但是当我清除最近的应用程序时,接收器没有触发.我在这里搜索了很多......我们大多数人都说当一个应用程序处于 STOPPED_STATE 时,它不会收到任何关于特定事情发生的通知.

If the App is opened its just working fine. The receiver triggers good... but when i clear recent apps receiver not triggering. I searched a lot here.. and Most of us saying that when an app in STOPPED_STATE it wont receive any notification that the particular thing happened.

我有一个 android 设备 Hauwei 和 android 版本 4.4.4,当我清除我最近的应用程序时,它完全破坏了我的应用程序.接收器停止工作.

I have an android device Hauwei and android version 4.4.4 and when i clear my recent application it completely destroy my app. the receiver stopped working.

我尝试创建一个服务并返回 start_sticky,对我来说,它只可能用于前台进程,而不用于后台任务.但我不想推送通知,上面写着 myApplication 在您的设备中运行.

I have tried to make an service and return start_sticky and for me its only possible with foreground process not for background tasks. But i don't want to push a notification which says myApplication running in your device.

现在我想要的是我需要一个即使应用程序关闭也应该接收 SMS_RECEIVED 的接收器(这里我不是在谈论应用程序的 STOPPED_STATE).

Now What i want is I need A receiver which should receive SMS_RECEIVED even if the app is closed (here I am not talking about the STOPPED_STATE OF THE APP).

在 clearRecentApps myApp 处于 STOPPED_STATE 之后(我可以在设置 myApps FORCE_STOP 按钮禁用时看到它).但同时 WATSAPP 、 FACEBOOK 和 CLASSOFCLANS 不是 STOPPED_STATE(在设置中那些 FORCE_STOP 按钮仅启用).没有任何前台通知.

After clearRecentApps myApp is in STOPPED_STATE (i can see it in settings myApps FORCE_STOP button disabled). but at the same time WATSAPP , FACEBOOK AND CLASSOFCLANS are not it STOPPED_STATE( in settings those FORCE_STOP BUTTONS ARE ENABLED ONLY). without any foreground notifications.

他们怎么样...请帮帮我...这对我来说花了很多天...

How do they doing... Please help me guys... this taking lot of days for me..

如果我错了,请告诉我.我是 android 新手.. 任何帮助将不胜感激..

If i am wrong let me Know. Iam New to android.. Any Help would be appreciated..

推荐答案

这可能是一种变通方法,但要在应用关闭时保持服务运行,您必须重新启动服务在您的服务 onDestroy() 方法中.

This may be a work around but to keep your service running even when your app is closed, you have to start your service again in your service's onDestroy() method.

@Override
public void onDestroy() {
    super.onDestroy();
    startService(new Intent(this, YourServiceClass.class));

}

这篇关于如果我关闭最近的应用程序,BroadcastReceiver 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆