Move the service binder to a static inner class.

Should help to avoid potential memory leaks.

Change-Id: Ic9518af17d818eb439358cb86afa03e80ab9799e
This commit is contained in:
Artur Dryomov
2013-09-13 02:23:03 +03:00
parent ec49173e3a
commit dd887afe21
6 changed files with 18 additions and 12 deletions

View File

@@ -111,7 +111,7 @@ public class SlideShowActivity extends SherlockFragmentActivity implements Servi
@Override
public void onServiceConnected(ComponentName mComponentName, IBinder aBinder) {
CommunicationService.CBinder aServiceBinder = (CommunicationService.CBinder) aBinder;
CommunicationService.ServiceBinder aServiceBinder = (CommunicationService.ServiceBinder) aBinder;
mCommunicationService = aServiceBinder.getService();
startSlideShow();

View File

@@ -20,6 +20,18 @@ import org.libreoffice.impressremote.util.BluetoothOperator;
import org.libreoffice.impressremote.util.Intents;
public class CommunicationService extends Service implements Runnable, MessagesListener, Timer.TimerListener {
public static final class ServiceBinder extends Binder {
private final CommunicationService mCommunicationService;
public ServiceBinder(CommunicationService aCommunicationService) {
mCommunicationService = aCommunicationService;
}
public CommunicationService getService() {
return mCommunicationService;
}
}
private IBinder mBinder;
private ServersManager mServersManager;
@@ -37,7 +49,7 @@ public class CommunicationService extends Service implements Runnable, MessagesL
@Override
public void onCreate() {
mBinder = new CBinder();
mBinder = new ServiceBinder(this);
mServersManager = new ServersManager(this);
@@ -48,12 +60,6 @@ public class CommunicationService extends Service implements Runnable, MessagesL
mSlideShow = new SlideShow(mTimer);
}
public class CBinder extends Binder {
public CommunicationService getService() {
return CommunicationService.this;
}
}
private void saveBluetoothState() {
mBluetoothState = BluetoothOperator.getState();
}

View File

@@ -135,7 +135,7 @@ public class ComputerConnectionFragment extends SherlockFragment implements Serv
@Override
public void onServiceConnected(ComponentName aComponentName, IBinder aBinder) {
CommunicationService.CBinder aServiceBinder = (CommunicationService.CBinder) aBinder;
CommunicationService.ServiceBinder aServiceBinder = (CommunicationService.ServiceBinder) aBinder;
mCommunicationService = aServiceBinder.getService();
connectComputer();

View File

@@ -124,7 +124,7 @@ public class ComputersFragment extends SherlockListFragment implements ServiceCo
@Override
public void onServiceConnected(ComponentName aComponentName, IBinder aBinder) {
CommunicationService.CBinder aServiceBinder = (CommunicationService.CBinder) aBinder;
CommunicationService.ServiceBinder aServiceBinder = (CommunicationService.ServiceBinder) aBinder;
mCommunicationService = aServiceBinder.getService();
startComputersSearch();

View File

@@ -57,7 +57,7 @@ public class SlidesGridFragment extends SherlockFragment implements ServiceConne
@Override
public void onServiceConnected(ComponentName aComponentName, IBinder aBinder) {
CommunicationService.CBinder aServiceBinder = (CommunicationService.CBinder) aBinder;
CommunicationService.ServiceBinder aServiceBinder = (CommunicationService.ServiceBinder) aBinder;
mCommunicationService = aServiceBinder.getService();
setUpSlidesGrid();

View File

@@ -61,7 +61,7 @@ public class SlidesPagerFragment extends SherlockFragment implements ServiceConn
@Override
public void onServiceConnected(ComponentName aComponentName, IBinder aBinder) {
CommunicationService.CBinder aServiceBinder = (CommunicationService.CBinder) aBinder;
CommunicationService.ServiceBinder aServiceBinder = (CommunicationService.ServiceBinder) aBinder;
mCommunicationService = aServiceBinder.getService();
setUpSlidesPager();