I have an Android application similar to Uber or Snapp (an app like Uber in Iran) that receives data from a server through a foreground service. I want to achieve two things:
Display a notification when a new message is received.
Ensure the service starts if the app is closed, and reopens the application if it’s closed.
How can I implement these features?
I implemented a foreground service that receives data from the server.
I used NotificationManager to display notifications when new data is received.
I attempted to use START_STICKY in the service to make it restart if the app is closed.
I expected the service to continuously run in the background, even if the app is closed.
I expected the app to open automatically when a new message is received and a notification is shown.