0

Given

  1. Target OS versions: 4.4 – 10;
  2. App meant to be published in Google Play;
  3. App idea is public transport tracking (notifying when the specific bus is about to arrive to specific bus stop).

Problem

I was working on implementing notifications that will be displayed after app is closed/killed, facing some issues earlier. But, then, when I found solution, all works fine. I thought it did.

I have been testing notifications again, and noticed, that, after app closing or killing, notifications are appeared but only during 1-2 minutes after closing/killing. Then noting is working (I also tested toast, etc.)

I started googling, and read about Doze (I am testing on Android 8.1). I went to settings and turned off battery optimization for my app. Now notifications are displayed and after 1-2 minutes, all is working.

Question

At the same time Telegram, Instagram and others apps that always display notifications, after 1 minute or 1 hour, are battery optimized.

How do they display notification in Doze?


I read about Firebase. I hope this is not the only one solution. And currently, I even didn’t understand how it can help, but even, if can, if it is the only solution it is very stupid.

  • Are you using high priority fcm notifications? – Rajesh.k Mar 15 '21 at 10:39
  • @Rajesh.k I do not use FCM currently. I am using solution I mentioned in post. – Thawbkisavv Mar 15 '21 at 11:04
  • For your problem you can make your service as foreground service. example service code can be found here. https://github.com/android/location-samples/blob/master/LocationUpdatesForegroundService/app/src/main/java/com/google/android/gms/location/sample/locationupdatesforegroundservice/LocationUpdatesService.java – Rajesh.k Mar 15 '21 at 11:14
  • @Rajesh.k thank You, I will try it, but it seems to be pretty similar to what I already have. Did You read the solution I mentioned in the current question, and origin, where I took it from (https://stackoverflow.com/questions/30525784/android-keep-service-running-when-app-is-killed/52258125#52258125)? – Thawbkisavv Mar 15 '21 at 11:22
  • The solution mentioned in that link is not official way to implement foreground service. it will cause problems like showing notification " the app is running in the background". so build proper notification object for startforeground method. – Rajesh.k Mar 16 '21 at 11:27
  • @Rajesh.k ok I’ll try, though I haven’t faced that problems, You write about. – Thawbkisavv Mar 18 '21 at 07:23

0 Answers0