My service works with android 7.1.1 but not with android 9Is there a way to run Python on Android?How to save an Android Activity state using save instance state?How to check if a service is running on Android?Close/hide the Android Soft KeyboardWhy is the Android emulator so slow? How can we speed up the Android emulator?“Debug certificate expired” error in Eclipse Android pluginsIs there a unique Android device ID?What is 'Context' on Android?Proper use cases for Android UserManager.isUserAGoat()?Service vs IntentService

To find islands of 1 and 0 in matrix

Suggestions for protecting jeans from saddle clamp bolt

How do I explain an exponentially complex intuitively?

What is the most common end of life issue for a car?

Does the Intel 8086 CPU have user mode and kernel mode?

If Trump gets impeached, how long would Pence be president?

Send a single HTML email from Thunderbird, overriding the default "plain text" setting

How to check what is edible on an alien world?

Why was Sauron preparing for war instead of trying to find the ring?

Trapped in an ocean Temple in Minecraft?

How to store my pliers and wire cutters on my desk?

What do I do with a party that is much stronger than their level?

Twelve past eleven at the police station

TSA asking to see cell phone

Japanese reading of an integer

If my pay period is split between 2 calendar years, which tax year do I file them in?

Assuring luggage isn't lost with short layover

Where to place an artificial gland in the human body?

Why does Canada require mandatory bilingualism in all government posts?

How to handle academic references for US PhD program, when I have been out of academia for a (very) long time?

Decreasing star size

How to judge a Ph.D. applicant that arrives "out of thin air"

Where to find an interactive PDF or HTML version of the tex.web documentation?

Why can't my huge trees be chopped down?



My service works with android 7.1.1 but not with android 9


Is there a way to run Python on Android?How to save an Android Activity state using save instance state?How to check if a service is running on Android?Close/hide the Android Soft KeyboardWhy is the Android emulator so slow? How can we speed up the Android emulator?“Debug certificate expired” error in Eclipse Android pluginsIs there a unique Android device ID?What is 'Context' on Android?Proper use cases for Android UserManager.isUserAGoat()?Service vs IntentService






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















My app uses a background service to listen to GPS position changes. It works on android 7.1.1 (even if my activity is closed or the screen is turn off). When I tried it on android 9 (with the AVD) it only works when the activity is in the foreground, otherwise not. It looks like the service is stopped when the app is closed. minSdkVersion is set to 23. Why app have different behavior on different API? Android does not guarantee the compatibility of apps on newer OS versions?



public class MainActivity extends AppCompatActivity 

@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

/**code to request permission*/

startService(new Intent(this, EventControllerService.class));




public final class EventControllerService extends Service
private final static int MIN_TIME_FOR_GPS_UPDATES = 1;
private final static float MIN_METER_FOR_GPS_UPDATES = 10.0f;
private static NotificationManager mNotificationManager;
private final BroadcastReceiver receiverDNDChange = new BroadcastReceiver()
@Override
public void onReceive(Context context, Intent intent)
//work on receive

;
private final EventControllerService self = this;
private final LocationListener locationListener = new LocationListener()
@Override
public void onLocationChanged(Location location)
Toast.makeText(self, "DENTRO", Toast.LENGTH_LONG).show();
try
//work to do on position change
catch (SecurityException ignored)
stopSelf();



@Override
public void onStatusChanged(String provider, int status, Bundle extras)


@Override
public void onProviderEnabled(String provider)


@Override
public void onProviderDisabled(String provider)

;

@Override
public void onCreate()
super.onCreate();
try
mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

IntentFilter filter = new IntentFilter();
filter.addAction(NotificationManager.ACTION_INTERRUPTION_FILTER_CHANGED);
registerReceiver(receiverDNDChange, filter);

LocationManager mLocationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, MIN_TIME_FOR_GPS_UPDATES, MIN_METER_FOR_GPS_UPDATES, locationListener);
catch (SecurityException ignored)
stopSelf();



@Override
public IBinder onBind(Intent intent)
return null;



<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="marcomantovani.pcd.silentmap">

<uses-permission android:name="android.permission.ACCESS_NOTIFICATION_POLICY" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />


<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:ignore="AllowBackup,GoogleAppIndexingWarning">
<service android:name=".EventControllerService"/>
<receiver android:name="marcomantovani.pcd.silentmap.AutoStart">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>


How can I change code to avoid this problem?










share|improve this question






























    0















    My app uses a background service to listen to GPS position changes. It works on android 7.1.1 (even if my activity is closed or the screen is turn off). When I tried it on android 9 (with the AVD) it only works when the activity is in the foreground, otherwise not. It looks like the service is stopped when the app is closed. minSdkVersion is set to 23. Why app have different behavior on different API? Android does not guarantee the compatibility of apps on newer OS versions?



    public class MainActivity extends AppCompatActivity 

    @Override
    protected void onCreate(Bundle savedInstanceState)
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    /**code to request permission*/

    startService(new Intent(this, EventControllerService.class));




    public final class EventControllerService extends Service
    private final static int MIN_TIME_FOR_GPS_UPDATES = 1;
    private final static float MIN_METER_FOR_GPS_UPDATES = 10.0f;
    private static NotificationManager mNotificationManager;
    private final BroadcastReceiver receiverDNDChange = new BroadcastReceiver()
    @Override
    public void onReceive(Context context, Intent intent)
    //work on receive

    ;
    private final EventControllerService self = this;
    private final LocationListener locationListener = new LocationListener()
    @Override
    public void onLocationChanged(Location location)
    Toast.makeText(self, "DENTRO", Toast.LENGTH_LONG).show();
    try
    //work to do on position change
    catch (SecurityException ignored)
    stopSelf();



    @Override
    public void onStatusChanged(String provider, int status, Bundle extras)


    @Override
    public void onProviderEnabled(String provider)


    @Override
    public void onProviderDisabled(String provider)

    ;

    @Override
    public void onCreate()
    super.onCreate();
    try
    mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    IntentFilter filter = new IntentFilter();
    filter.addAction(NotificationManager.ACTION_INTERRUPTION_FILTER_CHANGED);
    registerReceiver(receiverDNDChange, filter);

    LocationManager mLocationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
    mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, MIN_TIME_FOR_GPS_UPDATES, MIN_METER_FOR_GPS_UPDATES, locationListener);
    catch (SecurityException ignored)
    stopSelf();



    @Override
    public IBinder onBind(Intent intent)
    return null;



    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="marcomantovani.pcd.silentmap">

    <uses-permission android:name="android.permission.ACCESS_NOTIFICATION_POLICY" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />


    <application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme"
    tools:ignore="AllowBackup,GoogleAppIndexingWarning">
    <service android:name=".EventControllerService"/>
    <receiver android:name="marcomantovani.pcd.silentmap.AutoStart">
    <intent-filter>
    <action android:name="android.intent.action.BOOT_COMPLETED" />
    </intent-filter>
    </receiver>
    <activity android:name=".MainActivity">
    <intent-filter>
    <action android:name="android.intent.action.MAIN" />

    <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
    </activity>
    </application>

    </manifest>


    How can I change code to avoid this problem?










    share|improve this question


























      0












      0








      0








      My app uses a background service to listen to GPS position changes. It works on android 7.1.1 (even if my activity is closed or the screen is turn off). When I tried it on android 9 (with the AVD) it only works when the activity is in the foreground, otherwise not. It looks like the service is stopped when the app is closed. minSdkVersion is set to 23. Why app have different behavior on different API? Android does not guarantee the compatibility of apps on newer OS versions?



      public class MainActivity extends AppCompatActivity 

      @Override
      protected void onCreate(Bundle savedInstanceState)
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);

      /**code to request permission*/

      startService(new Intent(this, EventControllerService.class));




      public final class EventControllerService extends Service
      private final static int MIN_TIME_FOR_GPS_UPDATES = 1;
      private final static float MIN_METER_FOR_GPS_UPDATES = 10.0f;
      private static NotificationManager mNotificationManager;
      private final BroadcastReceiver receiverDNDChange = new BroadcastReceiver()
      @Override
      public void onReceive(Context context, Intent intent)
      //work on receive

      ;
      private final EventControllerService self = this;
      private final LocationListener locationListener = new LocationListener()
      @Override
      public void onLocationChanged(Location location)
      Toast.makeText(self, "DENTRO", Toast.LENGTH_LONG).show();
      try
      //work to do on position change
      catch (SecurityException ignored)
      stopSelf();



      @Override
      public void onStatusChanged(String provider, int status, Bundle extras)


      @Override
      public void onProviderEnabled(String provider)


      @Override
      public void onProviderDisabled(String provider)

      ;

      @Override
      public void onCreate()
      super.onCreate();
      try
      mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

      IntentFilter filter = new IntentFilter();
      filter.addAction(NotificationManager.ACTION_INTERRUPTION_FILTER_CHANGED);
      registerReceiver(receiverDNDChange, filter);

      LocationManager mLocationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
      mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, MIN_TIME_FOR_GPS_UPDATES, MIN_METER_FOR_GPS_UPDATES, locationListener);
      catch (SecurityException ignored)
      stopSelf();



      @Override
      public IBinder onBind(Intent intent)
      return null;



      <?xml version="1.0" encoding="utf-8"?>
      <manifest xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      package="marcomantovani.pcd.silentmap">

      <uses-permission android:name="android.permission.ACCESS_NOTIFICATION_POLICY" />
      <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
      <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
      <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />


      <application
      android:allowBackup="true"
      android:icon="@mipmap/ic_launcher"
      android:label="@string/app_name"
      android:roundIcon="@mipmap/ic_launcher_round"
      android:supportsRtl="true"
      android:theme="@style/AppTheme"
      tools:ignore="AllowBackup,GoogleAppIndexingWarning">
      <service android:name=".EventControllerService"/>
      <receiver android:name="marcomantovani.pcd.silentmap.AutoStart">
      <intent-filter>
      <action android:name="android.intent.action.BOOT_COMPLETED" />
      </intent-filter>
      </receiver>
      <activity android:name=".MainActivity">
      <intent-filter>
      <action android:name="android.intent.action.MAIN" />

      <category android:name="android.intent.category.LAUNCHER" />
      </intent-filter>
      </activity>
      </application>

      </manifest>


      How can I change code to avoid this problem?










      share|improve this question
















      My app uses a background service to listen to GPS position changes. It works on android 7.1.1 (even if my activity is closed or the screen is turn off). When I tried it on android 9 (with the AVD) it only works when the activity is in the foreground, otherwise not. It looks like the service is stopped when the app is closed. minSdkVersion is set to 23. Why app have different behavior on different API? Android does not guarantee the compatibility of apps on newer OS versions?



      public class MainActivity extends AppCompatActivity 

      @Override
      protected void onCreate(Bundle savedInstanceState)
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);

      /**code to request permission*/

      startService(new Intent(this, EventControllerService.class));




      public final class EventControllerService extends Service
      private final static int MIN_TIME_FOR_GPS_UPDATES = 1;
      private final static float MIN_METER_FOR_GPS_UPDATES = 10.0f;
      private static NotificationManager mNotificationManager;
      private final BroadcastReceiver receiverDNDChange = new BroadcastReceiver()
      @Override
      public void onReceive(Context context, Intent intent)
      //work on receive

      ;
      private final EventControllerService self = this;
      private final LocationListener locationListener = new LocationListener()
      @Override
      public void onLocationChanged(Location location)
      Toast.makeText(self, "DENTRO", Toast.LENGTH_LONG).show();
      try
      //work to do on position change
      catch (SecurityException ignored)
      stopSelf();



      @Override
      public void onStatusChanged(String provider, int status, Bundle extras)


      @Override
      public void onProviderEnabled(String provider)


      @Override
      public void onProviderDisabled(String provider)

      ;

      @Override
      public void onCreate()
      super.onCreate();
      try
      mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

      IntentFilter filter = new IntentFilter();
      filter.addAction(NotificationManager.ACTION_INTERRUPTION_FILTER_CHANGED);
      registerReceiver(receiverDNDChange, filter);

      LocationManager mLocationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
      mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, MIN_TIME_FOR_GPS_UPDATES, MIN_METER_FOR_GPS_UPDATES, locationListener);
      catch (SecurityException ignored)
      stopSelf();



      @Override
      public IBinder onBind(Intent intent)
      return null;



      <?xml version="1.0" encoding="utf-8"?>
      <manifest xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      package="marcomantovani.pcd.silentmap">

      <uses-permission android:name="android.permission.ACCESS_NOTIFICATION_POLICY" />
      <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
      <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
      <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />


      <application
      android:allowBackup="true"
      android:icon="@mipmap/ic_launcher"
      android:label="@string/app_name"
      android:roundIcon="@mipmap/ic_launcher_round"
      android:supportsRtl="true"
      android:theme="@style/AppTheme"
      tools:ignore="AllowBackup,GoogleAppIndexingWarning">
      <service android:name=".EventControllerService"/>
      <receiver android:name="marcomantovani.pcd.silentmap.AutoStart">
      <intent-filter>
      <action android:name="android.intent.action.BOOT_COMPLETED" />
      </intent-filter>
      </receiver>
      <activity android:name=".MainActivity">
      <intent-filter>
      <action android:name="android.intent.action.MAIN" />

      <category android:name="android.intent.category.LAUNCHER" />
      </intent-filter>
      </activity>
      </application>

      </manifest>


      How can I change code to avoid this problem?







      android android-service android-location android-broadcastreceiver






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 26 at 19:03







      Marco Mantovani

















      asked Mar 26 at 18:51









      Marco MantovaniMarco Mantovani

      331 silver badge5 bronze badges




      331 silver badge5 bronze badges






















          2 Answers
          2






          active

          oldest

          votes


















          2














          I understand you read this:
          https://developer.android.com/about/versions/oreo/background



          There are many changes related to background services and especially GPS in Android 9. Note this also (so targeting API23 is not a solution):




          By default, these changes only affect apps that target Android 8.0 (API level 26) or higher. However, users can enable these restrictions for any app from the Settings screen, even if the app targets an API level lower than 26. You may need to update your app to comply with the new limitations.




          What you can do right now and how we make it work in our apps. Migrate your service to compatible with Android 9. I suggest using:



          startForegroundService()



          Make your service to run on foreground. It's a small change. Just change one flag nad start your service this way.



          Show notification that your app is working (this will keep your app working even when user is leaving the app otherwise - Android OS will limit your service)



          Targeting API23 is a bad idea also because of this:




          Starting August 1, 2019, Google Play requires that new apps target at least Android 9.0 (API level 28), and that app updates target Android 9.0 from November 1, 2019. Until these dates, new apps and app updates must target at least Android 8.0 (API level 26).




          TL;DR
          1. Migrate service to foreground
          2. Create simple notification that will tell your user that app is working
          3. Start service with startForeground()






          share|improve this answer






























            0














            Android has been steadily moving to restrict the access given to an app in the background. Location services were restricted from Android 8.



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






            share|improve this answer

























              Your Answer






              StackExchange.ifUsing("editor", function ()
              StackExchange.using("externalEditor", function ()
              StackExchange.using("snippets", function ()
              StackExchange.snippets.init();
              );
              );
              , "code-snippets");

              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "1"
              ;
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function()
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled)
              StackExchange.using("snippets", function()
              createEditor();
              );

              else
              createEditor();

              );

              function createEditor()
              StackExchange.prepareEditor(
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader:
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              ,
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              );



              );













              draft saved

              draft discarded


















              StackExchange.ready(
              function ()
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55364361%2fmy-service-works-with-android-7-1-1-but-not-with-android-9%23new-answer', 'question_page');

              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              2














              I understand you read this:
              https://developer.android.com/about/versions/oreo/background



              There are many changes related to background services and especially GPS in Android 9. Note this also (so targeting API23 is not a solution):




              By default, these changes only affect apps that target Android 8.0 (API level 26) or higher. However, users can enable these restrictions for any app from the Settings screen, even if the app targets an API level lower than 26. You may need to update your app to comply with the new limitations.




              What you can do right now and how we make it work in our apps. Migrate your service to compatible with Android 9. I suggest using:



              startForegroundService()



              Make your service to run on foreground. It's a small change. Just change one flag nad start your service this way.



              Show notification that your app is working (this will keep your app working even when user is leaving the app otherwise - Android OS will limit your service)



              Targeting API23 is a bad idea also because of this:




              Starting August 1, 2019, Google Play requires that new apps target at least Android 9.0 (API level 28), and that app updates target Android 9.0 from November 1, 2019. Until these dates, new apps and app updates must target at least Android 8.0 (API level 26).




              TL;DR
              1. Migrate service to foreground
              2. Create simple notification that will tell your user that app is working
              3. Start service with startForeground()






              share|improve this answer



























                2














                I understand you read this:
                https://developer.android.com/about/versions/oreo/background



                There are many changes related to background services and especially GPS in Android 9. Note this also (so targeting API23 is not a solution):




                By default, these changes only affect apps that target Android 8.0 (API level 26) or higher. However, users can enable these restrictions for any app from the Settings screen, even if the app targets an API level lower than 26. You may need to update your app to comply with the new limitations.




                What you can do right now and how we make it work in our apps. Migrate your service to compatible with Android 9. I suggest using:



                startForegroundService()



                Make your service to run on foreground. It's a small change. Just change one flag nad start your service this way.



                Show notification that your app is working (this will keep your app working even when user is leaving the app otherwise - Android OS will limit your service)



                Targeting API23 is a bad idea also because of this:




                Starting August 1, 2019, Google Play requires that new apps target at least Android 9.0 (API level 28), and that app updates target Android 9.0 from November 1, 2019. Until these dates, new apps and app updates must target at least Android 8.0 (API level 26).




                TL;DR
                1. Migrate service to foreground
                2. Create simple notification that will tell your user that app is working
                3. Start service with startForeground()






                share|improve this answer

























                  2












                  2








                  2







                  I understand you read this:
                  https://developer.android.com/about/versions/oreo/background



                  There are many changes related to background services and especially GPS in Android 9. Note this also (so targeting API23 is not a solution):




                  By default, these changes only affect apps that target Android 8.0 (API level 26) or higher. However, users can enable these restrictions for any app from the Settings screen, even if the app targets an API level lower than 26. You may need to update your app to comply with the new limitations.




                  What you can do right now and how we make it work in our apps. Migrate your service to compatible with Android 9. I suggest using:



                  startForegroundService()



                  Make your service to run on foreground. It's a small change. Just change one flag nad start your service this way.



                  Show notification that your app is working (this will keep your app working even when user is leaving the app otherwise - Android OS will limit your service)



                  Targeting API23 is a bad idea also because of this:




                  Starting August 1, 2019, Google Play requires that new apps target at least Android 9.0 (API level 28), and that app updates target Android 9.0 from November 1, 2019. Until these dates, new apps and app updates must target at least Android 8.0 (API level 26).




                  TL;DR
                  1. Migrate service to foreground
                  2. Create simple notification that will tell your user that app is working
                  3. Start service with startForeground()






                  share|improve this answer













                  I understand you read this:
                  https://developer.android.com/about/versions/oreo/background



                  There are many changes related to background services and especially GPS in Android 9. Note this also (so targeting API23 is not a solution):




                  By default, these changes only affect apps that target Android 8.0 (API level 26) or higher. However, users can enable these restrictions for any app from the Settings screen, even if the app targets an API level lower than 26. You may need to update your app to comply with the new limitations.




                  What you can do right now and how we make it work in our apps. Migrate your service to compatible with Android 9. I suggest using:



                  startForegroundService()



                  Make your service to run on foreground. It's a small change. Just change one flag nad start your service this way.



                  Show notification that your app is working (this will keep your app working even when user is leaving the app otherwise - Android OS will limit your service)



                  Targeting API23 is a bad idea also because of this:




                  Starting August 1, 2019, Google Play requires that new apps target at least Android 9.0 (API level 28), and that app updates target Android 9.0 from November 1, 2019. Until these dates, new apps and app updates must target at least Android 8.0 (API level 26).




                  TL;DR
                  1. Migrate service to foreground
                  2. Create simple notification that will tell your user that app is working
                  3. Start service with startForeground()







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Mar 26 at 19:03









                  adekadek

                  2,4562 gold badges22 silver badges40 bronze badges




                  2,4562 gold badges22 silver badges40 bronze badges























                      0














                      Android has been steadily moving to restrict the access given to an app in the background. Location services were restricted from Android 8.



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






                      share|improve this answer



























                        0














                        Android has been steadily moving to restrict the access given to an app in the background. Location services were restricted from Android 8.



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






                        share|improve this answer

























                          0












                          0








                          0







                          Android has been steadily moving to restrict the access given to an app in the background. Location services were restricted from Android 8.



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






                          share|improve this answer













                          Android has been steadily moving to restrict the access given to an app in the background. Location services were restricted from Android 8.



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







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Mar 26 at 18:59









                          Anudeep BullaAnudeep Bulla

                          4,3863 gold badges18 silver badges26 bronze badges




                          4,3863 gold badges18 silver badges26 bronze badges



























                              draft saved

                              draft discarded
















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid


                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.

                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55364361%2fmy-service-works-with-android-7-1-1-but-not-with-android-9%23new-answer', 'question_page');

                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                              용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

                              155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해