但是,以下两种行为不是由任何活动触发的,而是由单击小部件本身(=后台)触发的,并且仅在预OREO设备上工作:
Not allowed to start service Intent
From developer.android.com :
IntentService受这些限制。IntentService是
针对Android 8.0或更高版本时,请不要正常工作。为了这个
但在运行时使用作业而不是服务
显示:
<service
android:name="com.example.MyWidgetService"
android:permission="android.permission.BIND_JOB_SERVICE"/>
public class MyWidgetService extends JobIntentService {
@Override
protected void onHandleWork(Intent intent) {
XLog.i("onHandleWork"); <-- never printed to log
}
}
remote.setOnClickPendingIntent(R.id.open, new Intent(..some-code..));
修改后的代码可以在预OREO设备上工作,但在OREO上,既不单击列表视图项,也不单击按钮,则不会调用myWidgetService.onHandleWork()。