App self termination? / USB Accessory 1/2 works

13 views
Skip to first unread message

John Whitmore

unread,
May 7, 2016, 5:25:39 PM5/7/16
to android-...@googlegroups.com
I know App self termination is frowned upon but I need it because Android's USB
Accessory mode only half works. I should say IMHO as I might have mis-read the
documentation.

Just to summarise when my Hardware device is powered up or plugged into the
Android device's USB then my Android App is auto started, because of what's in
my Manifest. That part works.

Now if the connected Hardware is disconnected or powers down my App receives a
message to say that the device has disconnected. That's fine I can clean up a
few data structures and wait.

Now with the App running when the Hardware is re-plugged in or powered up my
App does NOT receive the Attached message that I've subscribed for so my App
has no idea that it should do anything.

My interpretation is that I should receive an Attached message.

To get around this when the App receives a Detach event I have to self
terminate the App so that when the Hardware is attached I'll get the event.


SO that's my bit of USB 1/2 working, no for finish() I was trying to use the
finish() method but it seems to work sometimes but is fairly
unpredictable. I've taken to using System.exit(0) but that seems a bit heavy
handed. Still it works.

If anybody could suggest why either USB half works or finish() less then half
works I'd be grateful

<intent-filter>
<action android:name="android.hardware.usb.action.USB_ACCESSORY_ATTACHED" />
</intent-filter>

<intent-filter>
<action android:name="android.hardware.usb.action.ACTION_USB_ACCESSORY_DETACHED" />
</intent-filter>
Reply all
Reply to author
Forward
0 new messages