0

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.

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.

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.

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.

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

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

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

Mr.Popular
  • 845
  • 1
  • 8
  • 15
  • Yes, you need to use a Service here. in startService means in onCreate, register the recceiver and in onDestroy of Service unregister it. and startService with STICKY return. – Vinodh Dec 08 '16 at 06:18
  • I have tried it but it doesnt work.... If i clear Recent Apps My apps Service doesnt working... I dont know it stopped working – Mr.Popular Dec 08 '16 at 06:20
  • can you share code where you are registering the receiver? programmatically or manifest? – rafa Dec 08 '16 at 06:23
  • @rafa Iam putting My Receiver In manifest only.. I am not registering it by programatically – Mr.Popular Dec 08 '16 at 06:26
  • @Mr.Popular : What are you returning as startMode from onStartCommand ? – Vinodh Dec 08 '16 at 06:27
  • @rafa return START_STICKY; – Mr.Popular Dec 08 '16 at 06:39
  • I had a similar problem. Сheck my answer here https://stackoverflow.com/questions/40931966/android-alarmmanager-setexactandallowwhileidle-and-wakefulbroadcastreceiver-no/46043081#46043081 – Plo_Koon Sep 04 '17 at 19:33

1 Answers1

0

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));

}
Vivek Mishra
  • 5,669
  • 9
  • 46
  • 84