代码之家  ›  专栏  ›  技术社区  ›  Wolf359

android oreo+:appwidget click不调用jobintentservice.onhandlework()。

  •  1
  • Wolf359  · 技术社区  · 7 年前

    但是,以下两种行为不是由任何活动触发的,而是由单击小部件本身(=后台)触发的,并且仅在预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()。

    1 回复  |  直到 7 年前
        1
  •  2
  •   HeyAlex    7 年前