I've called startService in background.I run the application and send it to background immediately and I expect to see IllegalStateException
after 10 seconds in android 8, but it works without any exception. In onCreate of activity:
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
startService(new Intent(MainActivity.this, TestService.class));
}
}, 10000);
}
and in the service:
@Override
protected void onHandleIntent(@Nullable Intent intent) {
int i= 0;
do {
Log.i(TAG, "onHandleIntent: "+ i);
i++;
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
} while (i<100);
}
gradle:
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.example.usergood.test"
minSdkVersion 26
targetSdkVersion 26
versionCode 1
versionName "1.0"
}