Move the service binder to a static inner class.
Should help to avoid potential memory leaks. Change-Id: Ic9518af17d818eb439358cb86afa03e80ab9799e
This commit is contained in:
@@ -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();
|
||||
|
@@ -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();
|
||||
}
|
||||
|
@@ -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();
|
||||
|
@@ -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();
|
||||
|
@@ -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();
|
||||
|
@@ -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();
|
||||
|
Reference in New Issue
Block a user