Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/218.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 服务运行时没有Internet连接(活动已停止)_Android_Service - Fatal编程技术网

Android 服务运行时没有Internet连接(活动已停止)

Android 服务运行时没有Internet连接(活动已停止),android,service,Android,Service,我已经用谷歌找到了一个解决方案,但什么也没找到。 我有一个独立于活动运行的服务,但如果活动暂停/停止,该服务将无法连接到Internet。 我使用一个线程来告诉我连接的状态,当活动返回到前端时,一切正常 对于IntentService,它也有同样的问题 这是我的服务(缩小到重要部分): } 该服务是通过以下方式启动的: sIntent = new Intent(this, LoadService.class); pIntent = PendingIntent.getService(this, 0

我已经用谷歌找到了一个解决方案,但什么也没找到。 我有一个独立于活动运行的服务,但如果活动暂停/停止,该服务将无法连接到Internet。 我使用一个线程来告诉我连接的状态,当活动返回到前端时,一切正常

对于IntentService,它也有同样的问题

这是我的服务(缩小到重要部分):

}

该服务是通过以下方式启动的:

sIntent = new Intent(this, LoadService.class);
pIntent = PendingIntent.getService(this, 0, sIntent, 0);
pIntent.send();
sIntent = new Intent(this, LoadService.class);
pIntent = PendingIntent.getService(this, 0, sIntent, 0);
pIntent.send();