Broadcast receiver stop triggering when swipe clear the app

懵懂的女人 提交于 2019-12-06 07:36:33

In main app start/stop the service

Intent service = new Intent(context, MyService.class);
context.startService(service);
...
Intent service = new Intent(context, MyService.class);
context.stopService(service);

service

  public class MyService extends Service
    {
     private static BroadcastReceiver m_Receiver;

     @Override
     public IBinder onBind(Intent arg0)
     {
      return null;
     }
    @Override
  public int onStartCommand(Intent intent, int flags, int startId) {
    return START_STICKY;
    }

     @Override
     public void onCreate()
     {
      Receiver();
     }

     @Override
     public void onDestroy()
     {
     unregisterReceiver(m_Receiver);
     }

     private void Receiver()
     {
     m_Receiver = new BroadcastReceiver()
      {
       @Override
       public void onReceive(Context context, Intent intent)
       {
        //place all ur stuff here
       }
      }

     }
    }

It looks like the problem is on the server side ,

https://firebase.google.com/docs/cloud-messaging/concept-options

There are two types of messages

With FCM, you can send two types of messages to clients:

Notification messages, sometimes thought of as "display messages." Data messages, which are handled by the client app.

Basically change from notification to data on your server , this will call OnRecieve when app is closed.

Check the link for more info and examples

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!