aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Mattson <jmatt@google.com>2011-04-01 17:10:48 -0700
committerErik Gilling <konkers@android.com>2011-04-04 09:56:42 -0700
commit29cedd33b4addee662d5a0347719d5fcb07edeb0 (patch)
treede3c67065d783651d0c1cb4dd4818c206f46e7f2
parent857b9aa769edc3280445baa361b7dd6d99169f0f (diff)
downloaddemokit-29cedd33b4addee662d5a0347719d5fcb07edeb0.tar.gz
Fix a crash after an orientation change
A result of the progress bars trying to call their onProgressChanged callback. On an orientation change, save the accessory being accessed and restore it appropriately in onCreate, skip accessory initialization in onResume in this case. Change-Id: I7b301153a9cd403159d63424dc8a96ba6ae28882
-rw-r--r--demokit/app/src/com/google/DemoKit/DemoKitActivity.java20
1 files changed, 19 insertions, 1 deletions
diff --git a/demokit/app/src/com/google/DemoKit/DemoKitActivity.java b/demokit/app/src/com/google/DemoKit/DemoKitActivity.java
index 338276f..bb1ec3a 100644
--- a/demokit/app/src/com/google/DemoKit/DemoKitActivity.java
+++ b/demokit/app/src/com/google/DemoKit/DemoKitActivity.java
@@ -190,6 +190,11 @@ public class DemoKitActivity extends Activity implements Runnable, SeekBar.OnSee
filter.addAction(UsbManager.ACTION_USB_ACCESSORY_DETACHED);
registerReceiver(mUsbReceiver, filter);
+ if (getLastNonConfigurationInstance() != null) {
+ mAccessory = (UsbAccessory) getLastNonConfigurationInstance();
+ openAccessory(mAccessory);
+ }
+
setContentView(R.layout.main);
mButton1Image = (ImageView)findViewById(R.id.button1Image);
@@ -244,11 +249,24 @@ public class DemoKitActivity extends Activity implements Runnable, SeekBar.OnSee
}
@Override
+ public Object onRetainNonConfigurationInstance() {
+ if (mAccessory != null) {
+ return mAccessory;
+ } else {
+ return super.onRetainNonConfigurationInstance();
+ }
+ }
+
+ @Override
public void onResume() {
super.onResume();
Intent intent = getIntent();
Log.d(TAG, "intent: " + intent);
+ if (mInputStream != null && mOutputStream != null) {
+ return;
+ }
+
UsbAccessory[] accessories = mUsbManager.getAccessoryList();
UsbAccessory accessory = (accessories == null ? null : accessories[0]);
if (accessory != null) {
@@ -492,7 +510,7 @@ public class DemoKitActivity extends Activity implements Runnable, SeekBar.OnSee
else if (seekBar == mServo3)
buffer[1] = 0x12;
- if (buffer[1] != -1) {
+ if (mOutputStream != null && buffer[1] != -1) {
try {
mOutputStream.write(buffer);
} catch (IOException e) {