I have a widget. Finishing the SettingsActivity loads data from the Internet and displays it inside a ListView. This works on pre-Oreo and Oreo devices.
But the following two behaviors are not triggered from any activity, but from clicks on the widget itself (= background) and work only on pre-Oreo devices :
Clicking on the ListView itself opens the browser to navigate to the url of that item.
Clicking on a button above the ListView opens the settings activity.
But on Oreo after getting exceptions like
Not allowed to start service Intent
I switched from IntentService to JobIntentService because :
IntentService is subject to these restrictions IntentService is a service, and is therefore subject to the new restrictions on background services. As a result, many apps that rely on IntentService do not work properly when targeting Android 8.0 or higher. For this reason, Android Support Library 26.0.0 introduces a new JobIntentService class, which provides the same functionality as IntentService but uses jobs instead of services when running on Android 8.0 or higher.
Manifest :
<service
android:name="com.example.MyWidgetService"
android:permission="android.permission.BIND_JOB_SERVICE"/>
Service :
public class MyWidgetService extends JobIntentService {
@Override
protected void onHandleWork(Intent intent) {
XLog.i("onHandleWork"); <-- never printed to log
}
}
In Widget's RemoteViewsService :
remote.setOnClickPendingIntent(R.id.open, new Intent(..some-code..));
The modified code works on pre-Oreo devices but on Oreo clicking neither on a list-view item nor on the button does nothing, MyWidgetService.onHandleWork() is never invoked.
Any idea what I'm doing wrong ?