lsr*_*rom 6 service android background-process android-8.0-oreo
我有一个非常具体的用例。我需要启动在Android 8引导时运行Web服务器的后台服务。有人可以推荐一种实现此目的的方法吗?(在Android O中)。
看来您再也无法在启动时启动后台服务了……还有另一种方法吗?JobService还是运行前台服务?我的代码可在8以下的Android上运行,但似乎无法在O上运行。
表现:
<receiver android:name=".ServiceStarter" android:enabled="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"></action>
</intent-filter>
</receiver>
Run Code Online (Sandbox Code Playgroud)
ServiceStarter(extends BroadcastReceiver):
@Override
public void onReceive(Context context, Intent intent) {
HTTPServerService.startService(context);
}
Run Code Online (Sandbox Code Playgroud)
HTTPServerService.startService()
context.startService(new Intent(context, HTTPServerService.class));
Run Code Online (Sandbox Code Playgroud)
我看过其他类似的问题,但似乎都无法回答我的特定问题。我感谢任何指示。
小智 0
您需要使用 JobIntentService 而不是常规服务。
https://developer.android.com/reference/android/support/v4/app/JobIntentService.html
| 归档时间: |
|
| 查看次数: |
5585 次 |
| 最近记录: |