I am implementing Cloud Messaging inside my android app. It was so easy until I encountered a big problem: My app seems to work fine and receive messages properly on Samsung devices but on my own device (that happens to be Huawei P9) the app some times doesn't receive any messages. Fortunately I found the problem: when I exit my App and turn off the screen, or clearing the recent apps, my app clears from background and never receives any messages again! (too bad! Why is that?!)
But if I goto Settings->Advanced->Battery->ProtectedApps and check my app as "Protected", my app would received messages even after truing off the screen and/or clearing recent apps. Very good indeed!
Now my question is: Is there anyway to make my app protected? I know there is some way however because when I went to Settings->Advanced->Battery->ProtectedApps many apps (such as Telegram, WeChat, etc) where protected by default! If there is no way to do such thing, how can my app receive notifications?
I also know that some apps like Facebook and ShareIt are installed on my device and are NOT PROTECTED but still receive notifications. How is that?