0

I have an application which is using for performance testing. However, this application always be kill in the background in about 5 min later. I want to know how to let it stay alive.(In API 23)

I have tried startForeground(), but it seems didn't work. I logout the oom_adj and oom_score_adj and get the result 3 and 200. Did it do some effect?

airlet
  • 1
  • https://developer.android.com/training/scheduling/wakelock – Abraham Mathew Jul 24 '19 at 09:52
  • Use services that persist in the background – dustblue Jul 24 '19 at 09:54
  • [refer the answers here to persist your service](https://stackoverflow.com/questions/30525784/android-keep-service-running-when-app-is-killed) – dustblue Jul 24 '19 at 09:56
  • thanks for the hardik to put forward the startwakefulService method. maybe I describe the problem is inappropriate, I want to apply the stay alive method above API 23 and many method has been cancelled in later API version. – airlet Jul 25 '19 at 08:23

1 Answers1

0

Use below

       Intent intent = new Intent();
        ComponentName componentName = new ComponentName(getPackageName(), <Your IntentService>.class.getName());
        // Start the service, keeping the device awake 
        try {
            startWakefulService(getApplicationContext(), intent.setComponent(componentName));
        } catch (Exception e) {

        }
Hardik Bambhania
  • 1,732
  • 15
  • 25
  • I've tried this method, but the developer document shows that This class was deprecated in API level 26.1.0, and I try to use it in API 27 and above – airlet Jul 25 '19 at 08:21