Those Python libraries that have been underestimated, see how many have you used? Wang


In the project, you need to start a service to play music. It happens to be a suspended. A few seconds of play disappeared for a few seconds. Android 8.0 itself limited it, and it seemed to go to Google. After Google, Google has limited the background of Android 8.0. It is mainly considered in performance. There will be problems with the suspension box and service startup. It is just that the project needs to be adapted. Specific restrictionsGOOGLE background limit

From the API of Android, at 26, Type_toast was replaced by Type_application_overlay, so you need to make the following adaptation in Android 8.0.

	mAudioParams.type = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
} else {
	mAudioParams.type = WindowManager.LayoutParams.TYPE_TOAST;

When starting the service, you need to use StartForegroundService. Google does not allow the service to start service in the background, unless you let the user know.

if (Build.VERSION.SDK_INT >= 26) {
        } else {

After the system creation service, it applies for five seconds to call the service’s StartForeground () method to show the notification of users who show the new service. Called in the OnStartCommand in the Service class.

			Notification.Builder builder = new Notification.Builder(this, "555").setContentTitle(getString(R.string.app_name)).setContentText("SmartTracker Running").setAutoCancel(true);
			Notification notification =;
			startForeground(1, notification);

above code can solve the above two problems, and one point is that the authority of the suspension box is remembered, otherwise the effect will not be visible.

Invite you to join, we grow up free of charge, just one second to change


Related Posts

SpringBoot and JWT integration

nr CSI (3) CQI

java four: optimization and use of Intellij IDEA 2021

Android 4.0.x Browser does not trigger the solution of the onTouchend event Zoewang

Those Python libraries that have been underestimated, see how many have you used? Wang

Random Posts

spring cloud netflix service found: Eureka (1) register and run WYX

[LCA] LCA’s tarjan writing POJ1330

2588: spoj 10628. Count on a Tree [Specific Line Tree+Double LCA]

Unity Positive hexagonal grid drawing (streamlined version)-code can be reused directly

python scrapy Explanation