I am currently using 2 services in my application:
1: LocationService basically tries to localize the user and strives to stay alive only when the application is in the foreground.
2: XmppService , which initiates a connection to the xmpp server, receives messages, sends them, logs out of the system ... and seeks to stay alive until the user logs out.
I read quite a lot of documentation, but I just can't figure it out.
I have Leaks when I try to save the LocationServiceBinder link, which is used to call my service functions (using AIDL interfaces). The same goes for Xmpp. When I untie, I sometimes get ANRs (which seem to be related to the fact that my bind / unbind are weird, onResume, onRestart ...).
The whole system works , but Iām sure that this is the wrong way to do this, and please, I would like after experienced people to return to the right side of the force! :)
Greetings
UPDATE
My location service contacts when the application starts, in order to complete the user position as quickly as possible:
if(callConnectService == null) { callConnectService = new ServiceConnection() { public void onServiceConnected(ComponentName name, IBinder binder) { locationServiceBinder = LocationServiceBinder.Stub.asInterface(binder); try { global.setLocationBinder(locationServiceBinder); global.getLocationBinder().startLocationListener(); } catch (Exception e){ Log.e(TAG, "Service binder ERROR"); } } public void onServiceDisconnected(ComponentName name) { locationServiceBinder = null; } }; } aimConServ = new Intent(this, LocationService.class); boolean bound = bindService(aimConServ,callConnectService,BIND_AUTO_CREATE);
My XMPp service starts when a user logs in:
callConnectService = new ServiceConnection () {
public void onServiceConnected(ComponentName name, IBinder binder) { try { Log.d(TAG, "[XMPP_INIT] Complete."); global.setServiceBinder(ConnectionServiceBinder.Stub.asInterface(binder));
and unlink each operation:
if (callConnectService != null){ unbindService(callConnectService); callConnectService = null; }