android-service-binding

Context.startForegroundService did not then call Service.startForeground: Alternative solution

烂漫一生 提交于 2019-12-11 03:24:10
问题 Note: This question assumes you know binding a service to a context. Everyone on the production is aware of this issue, or even some users that have an Android Oreo or Pie device. The exception looks like this: Fatal Exception: android.app.RemoteServiceException: Context.startForegroundService() did not then call Service.startForeground() at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1792) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop

Bind service from singleton

社会主义新天地 提交于 2019-12-10 21:57:35
问题 I have a started service that handles a connection and that keep an array of objects. On the other hand, I have a singleton that should bind to that service in order to get one of the objects handled by the service. So, how could I bind the service from the singleton? Is it a good practice to bind the service when the singleton is initialized by using the application's context? Is there a better alternative? Thanks in advance! 回答1: This is a perfectly good way to do it. Your singleton gets

Android: java.lang.IllegalArgumentException: Service not registered

我的未来我决定 提交于 2019-12-10 17:18:18
问题 I have activity, that starts service and binds it. But I want my service to run even if the activity is closed, so I need to unbind it. When i am trying to do so (calling my function disconnectFromService), i always get this exception. Service is successfuly bound and I can communicate with it. I am trying to unbind the service only if is bound. I think, I try to bind and unbind the service from the same context - this - calling bind and unbind are from MainActivity functions. Main Activity:

Is there a need to have one ServiceConnection per each Service bind?

拟墨画扇 提交于 2019-12-10 15:38:58
问题 I have several Android Service s that I want to bind to in my Activity , so I can monitor several actions from the user. To be able to bind every Service, and I will have several, do I need several private ServiceConnection s in my activity like the following? /** Defines callbacks for service binding, passed to bindService() */ private ServiceConnection mConnection = new ServiceConnection() { @Override public void onServiceConnected(ComponentName className, IBinder service) { // We've bound

IBinder casting *sometimes* results in ClassCastException when binding to service

狂风中的少年 提交于 2019-12-08 03:47:33
问题 We bind to our local service (same process) in Application subclass but sometimes we are getting a ClassCastException. I have no idea how to fix it since everyone says the exception occurs if the service process is different than your application. How can this be fixed? Application subclass: public class App extends Application implements ServiceConnection { private ServiceApi exposedServiceApi; private EventBus eventBus; @Override public void onCreate() { super.onCreate(); bindToService(); }

Binding and starting a service when application starts

主宰稳场 提交于 2019-12-07 23:57:30
I have a service in Android that encapsulates a framework that has a start method. The service boils down to something like this, many things omitted: public class MyService extends Service { private IBinder thisBinder; public MyService(){ thisBinder = new LocalBinder(); } @Override public IBinder onBind(Intent intent) { return thisBinder; } public void start(Map<String, Object> options) { getDriverManager().start(options); } } I also have a bridging class that makes calls to the service: public class MyServiceBridge implements ServiceConnection { private boolean started = false; private

binding a service to multiple activities

Deadly 提交于 2019-12-07 04:48:33
问题 My service is correctly binded to my first activity but when I try to bind it to a second activity it does not work Here is the code of onresume and on pause of my first activity @Override protected void onResume() { super.onResume(); connection = new ServiceConnection() { @Override public void onServiceDisconnected(ComponentName name) { service = null; } @Override public void onServiceConnected(ComponentName name, IBinder service) { shareInfos.this.service = (IService) service; } };

IBinder casting *sometimes* results in ClassCastException when binding to service

只愿长相守 提交于 2019-12-06 08:20:59
We bind to our local service (same process) in Application subclass but sometimes we are getting a ClassCastException. I have no idea how to fix it since everyone says the exception occurs if the service process is different than your application. How can this be fixed? Application subclass: public class App extends Application implements ServiceConnection { private ServiceApi exposedServiceApi; private EventBus eventBus; @Override public void onCreate() { super.onCreate(); bindToService(); } public void bindToService() { if (isConnectedToService()) { return; } boolean successfulBindCall =

java.lang.ClassCastException: android.os.BinderProxy cannot be cast to LocalBinder

不想你离开。 提交于 2019-12-05 17:16:06
问题 I have a Service that I am trying to bind to my main Activity , but I am receiving a java.lang.ClassCastException: android.os.BinderProxy cannot be cast to com.walintukai.rubix.ConnectionService$LocalBinder . I have declared the service in my manifest. Why is this happening? Manifest Declaration <service android:name=".ConnectionService" /> Service (simplified code) public class ConnectionService extends Service { static final String TAG = ConnectionService.class.getName(); private

binding a service to multiple activities

吃可爱长大的小学妹 提交于 2019-12-05 11:39:04
My service is correctly binded to my first activity but when I try to bind it to a second activity it does not work Here is the code of onresume and on pause of my first activity @Override protected void onResume() { super.onResume(); connection = new ServiceConnection() { @Override public void onServiceDisconnected(ComponentName name) { service = null; } @Override public void onServiceConnected(ComponentName name, IBinder service) { shareInfos.this.service = (IService) service; } }; bindService(new Intent(this, shareInfos.class), connection, Context.BIND_AUTO_CREATE); } @Override protected