Remove the notification "App is running in background"

Asked

Viewed 210 times

2

I fixed my app to work in the background with android 8 however many customers came to uninstall the application because of the permanent notification "App is running in background". I need my Intent Service running every x period without the notification appearing to the user.

In my Service I have the following code

@Override
public int onStartCommand(Intent intent, int flags, int startId) {


    Log.e("InBackground", "Serviço em background iniciado");

    Intent newIntent = new Intent(getBaseContext(),Service.class);
    newIntent.putExtra("comando","AtualizaInBackground");

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        String CHANNEL_ID = "my_channel_01";

        NotificationChannel channel = new NotificationChannel(CHANNEL_ID, "Atualizações em Background.", NotificationManager.IMPORTANCE_NONE);

        ((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)).createNotificationChannel(channel);

        Notification notification = new NotificationCompat.Builder(getBaseContext(), CHANNEL_ID)
                .setContentTitle("")
                .setContentText("").build();
        startForeground(1, notification);
    }
    startService(newIntent);


    return START_STICKY;
}
  • 1

    This might help https://answall.com/a/299957/2541

1 answer

1


From android 8 Google changed a number of things involving services on android.

I advise to take a look at the documentation as it has had several changes:

https://developer.android.com/about/versions/oreo/android-8.0-changes

https://developer.android.com/about/versions/oreo/background

From what I remember head-on if your app is not in the foreground Android will kill the services in x time (a few seconds), the easiest way to get around this is the way you did displaying a notification. I ended up using this method in my app too, so if anyone else has any other alternative is welcome :D

Browser other questions tagged

You are not signed in. Login or sign up in order to post.