Fixes a possible race condition and starting multiple instances (#559)

The onDestroyView method is used to unregister the application observer
from the dialog. However the parent got called first which destroys the
view of the dialog. This could lead to Null Pointer Exceptions when
the listener tries to update the UI of the dialog right after it was
destroyed.

The VolumeControllerDialogFragmentListener was created twice as creation
was triggered on both the down and up event of the volume keys. This has
been changed to only trigger on down events.
This commit is contained in:
Martijn Brekhof 2018-06-22 12:05:38 +02:00 committed by Synced Synapse
parent 796576eaa4
commit d11dbe6853
2 changed files with 4 additions and 2 deletions

View File

@ -124,13 +124,12 @@ public class VolumeControllerDialogFragmentListener extends AppCompatDialogFragm
@Override
public void onDestroyView() {
super.onDestroyView();
HostConnectionObserver hostConnectionObserver = hostManager.getHostConnectionObserver();
if (hostConnectionObserver != null) {
hostConnectionObserver.unregisterApplicationObserver(this);
}
unbinder.unbind();
super.onDestroyView();
}
private void registerObserver() {

View File

@ -290,6 +290,9 @@ public class RemoteActivity extends BaseActivity
*/
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
if (event.getAction() != KeyEvent.ACTION_DOWN)
return false;
boolean handled = VolumeControllerDialogFragmentListener.handleVolumeKeyEvent(this, event);
// Show volume change dialog if the event was handled and we are not in