Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/178.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 无法在后台启动服务_Android_Android Service_Android Service Binding - Fatal编程技术网

Android 无法在后台启动服务

Android 无法在后台启动服务,android,android-service,android-service-binding,Android,Android Service,Android Service Binding,我有一个用于监听套接字服务的服务。我只需要在应用程序处于前台时运行此服务。然而,在生产过程中,我看到了几起崩溃: IllegalStateException Not allowed to start service Intent { cmp=com.app.app/.app.sockets.EventHandlingService }: app is in background 起初,我在我的活动的onCreate中调用了这个,根据其他一些SO问题,从技术上讲,这个应用程序当时并没有前景化。所

我有一个用于监听套接字服务的服务。我只需要在应用程序处于前台时运行此服务。然而,在生产过程中,我看到了几起崩溃:

IllegalStateException
Not allowed to start service Intent { cmp=com.app.app/.app.sockets.EventHandlingService }: app is in background
起初,我在我的活动的onCreate中调用了这个,根据其他一些SO问题,从技术上讲,这个应用程序当时并没有前景化。所以我把它放到了简历上,但我仍然看到它的发生。这是如何启动的:

@Override
protected void onResume() {

    super.onResume();

    Intent serviceIntent = new Intent(this, EventHandlingService.class);
    startService(serviceIntent);
    bindService(serviceIntent, serviceConnection, 0);
}

我无法在本地复制此崩溃。

这是否回答了您的问题?不,这是关于如何在后台实际运行服务。我的问题是,我只在前台需要它,在onResume()中我希望应用程序在前台,所以我不明白为什么新的限制会影响我。你为什么同时使用startservice和bindservice?。我不明白这个用例。这能回答你的问题吗?不,这是关于如何在后台实际运行服务。我的问题是,我只在前台需要它,在onResume()中我希望应用程序在前台,所以我不明白为什么新的限制会影响我。你为什么同时使用startservice和bindservice?。我不明白这个用例。