Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Oreo persistent notification "App is running in the background"

I'm an Android app developer, and is developing an instant message app. The app has a notification problem on Android Oreo system, which shows persistent notification "App is running in the background" and cannot be cleared, and it's OK on system before Android Oreo.

Screenshot: The phone shows persistent notification App is running in the background

I find some discussion, such as Nexus Help Forum about this question, but it doesn't work in my phone's settings.

I want to know how to hide this notification programmatically and the app also can receive message instantly because it's an instant message app.

Any help is very appreciated.

like image 998
Smiles Avatar asked Sep 21 '17 04:09

Smiles


People also ask

How do I get rid of persistent notifications on Android?

To remove a persistent notification on Android as fast as possible, first, press-and-hold on it. Alternatively, swipe the notification left or right to reveal a gear icon on either side, and then tap on it. The notification expands. Tap on “Turn off notifications” at the bottom.

How turn off notification that App is running in the background?

Tap the three dot menu icon present at the top right corner and select Show system. Now under apps, scroll down and tap Android system followed by App notifications. Under app notifications scroll down and tap Apps running in background. Then tap Importance and choose Low from the options.

How do I stop apps running in the background Android 8?

Start the Settings app and tap Battery & device care. Then tap Battery. On the Battery page, head to Background usage limits. Here, you'll find three different lists of apps that have some form of power management enforced on them.


2 Answers

The app has a notification problem on Android Oreo system, which shows persistent notification "App is running in the background" and cannot be cleared, and it's OK on system before Android Oreo.

You used startForeground() with a minimum-importance Notification.

I want to know how to hide this notification programmatically

Use startForeground() with a Notification that has higher than minimum importance. Or, do not use startForeground().

I find some install message apps such as WeChat, Facebook doesn't have this problem on Android Oreo

They are not using foreground services, presumably. For example, they might be using Firebase Cloud Messaging (FCM).

like image 141
CommonsWare Avatar answered Nov 14 '22 20:11

CommonsWare


Before we talk about how to get rid of it, however, let’s talk about why it’s there in the first place.

Basically, in previous versions of Android, there was no real way of knowing if an app was running in the background doing a bunch of stuff it’s not supposed to be doing. In most scenarios, these misbehaving apps would wreak havoc on the battery by keeping the system awake—these are called “wakelocks.” In laymen’s terms, it was keeping the system from sleeping. That’s bad.

With Oreo, Google is calling out developers that let their apps do this sort of thing with the new notification. Essentially, if an app is running in the background and chewing up battery life, this new notification will tell you.

NOTE: There are a few legitimate scenarios where an app will continuously run in the background, like the VPN service running. Often, however, apps are running in the background unjustifiably.

It’s worth noting, though, removing the notification does not solve the issue. Period. There’s a reason this notification exists, and getting rid of it will do nothing to solve the underlying issue. You’ll either need to change a setting within the app or uninstall it altogether.

As long as you understand that and still want to remove it, let’s do this thing. Because this is a relatively crucial system setting, there’s no way within Oreo itself to remove it. That makes sense.

But like with most things, the developer community has found a way to remove it, and developer iboalali released an app to do just that. It’s actually just called “Hide ‘running in the background’ Notification,” which is about as straightforward as an app name could ever be. Go ahead and give it an install.

Without root, there is no way to actually prevent Android System from displaying the persistent “app is running in the background” notification in Android 8.0 Oreo. Looking at the source code for the ForegroundServiceController, its implementation, and the ForegroundServiceDialog doesn’t really reveal anything we can take advantage of. Programatically nothing have been found so far.

Here's a Blog post that can help you

like image 40
supro_96 Avatar answered Nov 14 '22 21:11

supro_96