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

查看:194
本文介绍了如果我关闭“最近使用的应用程序",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.

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

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..

如果我错了,请告诉我. Iam是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天全站免登陆