2
0
mirror of https://github.com/KDE/kdeconnect-android synced 2025-08-30 13:47:41 +00:00

Fixed a crash when pressing back from remote controls in action bar

Device activity isn't receiving the device id in that case.
This commit is contained in:
Albert Vaca 2013-10-03 15:51:15 +02:00
parent 5d00e6e168
commit 55e3861c5c

View File

@ -28,7 +28,7 @@ import java.util.HashMap;
public class DeviceActivity extends ActionBarActivity { public class DeviceActivity extends ActionBarActivity {
private String deviceId; static private String deviceId; //Static because if we get here by using the back button in the action bar, the extra deviceId will not be set.
private Device device; private Device device;
private Device.PluginsChangedListener pluginsChangedListener = new Device.PluginsChangedListener() { private Device.PluginsChangedListener pluginsChangedListener = new Device.PluginsChangedListener() {
@ -58,7 +58,7 @@ public class DeviceActivity extends ActionBarActivity {
errorList.setOnItemClickListener(new AdapterView.OnItemClickListener() { errorList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override @Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) { public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
Plugin p = failedPlugins.get(ids[position - 1]); //Header is position 0, so we have to substract one Plugin p = failedPlugins.get(ids[position - 1]); //Header is position 0, so we have to subtract one
p.getErrorDialog(DeviceActivity.this).show(); p.getErrorDialog(DeviceActivity.this).show();
} }
}); });
@ -91,12 +91,15 @@ public class DeviceActivity extends ActionBarActivity {
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_TITLE); actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_TITLE);
actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setDisplayHomeAsUpEnabled(true);
deviceId = getIntent().getStringExtra("deviceId"); if (getIntent().hasExtra("deviceId")) {
deviceId = getIntent().getStringExtra("deviceId");
}
BackgroundService.RunCommand(DeviceActivity.this, new BackgroundService.InstanceCallback() { BackgroundService.RunCommand(DeviceActivity.this, new BackgroundService.InstanceCallback() {
@Override @Override
public void onServiceStart(BackgroundService service) { public void onServiceStart(BackgroundService service) {
device = service.getDevice(deviceId); device = service.getDevice(deviceId);
if (device == null) return;
setTitle(device.getName()); setTitle(device.getName());
device.addPluginsChangedListener(pluginsChangedListener); device.addPluginsChangedListener(pluginsChangedListener);
pluginsChangedListener.onPluginsChanged(device); pluginsChangedListener.onPluginsChanged(device);