In my application, I want to start a service
when user is connected with the internet using manifest
declaration but in android
documentation connectivity broadcast
can only be registered inside a component. For that app should be running state. But I want to start the service
to show notification
independent of app state (running, paused, destroyed etc).
Simply I want to implement Gmail notification functionality in my app like Gmail shows notification when user is connected to internet independent of Gmail app state.Thanks!!
Asked
Active
Viewed 119 times
1
1 Answers
1
For anything you would want your application to do when it's not running, it has to be in a background service. You can implement a continuous check for the internet connectivity in that service.
Extend FirebaseMessagingService with your custom logic to listen to any FCM notification. https://firebase.google.com/docs/reference/android/com/google/firebase/messaging/FirebaseMessagingService

Vishal Raja
- 303
- 1
- 8
-
-
Extend FirebaseMessagingService with your custom logic to listen to any FCM notification. This service would continue to run even when your application is closed and would react to any FCM notification according to your custom logic. – Vishal Raja Jan 04 '18 at 13:00
-
-
So we have to start activity in some component right? So for this that component should be in running state – Shiv Jan 04 '18 at 13:13
-
If you're talking about the database changes on your server, you would need to identify those changes and send FCM notification to your application from your backend about those changes. – Vishal Raja Jan 04 '18 at 13:24
-
The component should run once to kick-start this background service and then can be closed. Your custom background service would keep running. – Vishal Raja Jan 04 '18 at 13:26
-
Yeah but without using any component how can I start service. Is there any way. – Shiv Jan 04 '18 at 13:39
-
1No. This is your application-specific service and application should run at least once to kick-start this service. At best, You can have this service started in the first application activity itself. No other way. – Vishal Raja Jan 04 '18 at 13:41
childAdded()
callback from real time database provided by firebase in background. – Shiv Jan 04 '18 at 12:34