Getting IOIO to restart after resuming an activity

63 views
Skip to first unread message

Tiffany Hwu

unread,
May 18, 2015, 6:19:35 PM5/18/15
to ioio-...@googlegroups.com
I have a main activity that extends IOIOActivity. Within this main activity I have function called scan(), which calls startActivityForResult() to open up a new activity to scan a QR code using the Android phone. The usual life cycle for main activity in this case is to pause, stop, let the QR activity scan, start, then resume. Accordingly, I think the 

IOIOAndroidApplicationHelper should reestablish the IOIO connection at the start stage. However, this doesn't happen and the IOIO connection is gone when the main activity resumes. Any ideas on why this is happening? I can post some code if more clarity is needed. Thanks!

Ytai Ben-Tsvi

unread,
May 19, 2015, 12:18:12 AM5/19/15
to ioio-...@googlegroups.com
Can you add some logs and figure out the exact sequence of lifecycle calls (e.g. onStart(), onStop(), etc.) in your scenario? Also include the relevant IOIO logs so we can see whether a connection is closed properly before switching.

On Mon, May 18, 2015 at 3:15 PM, Tiffany Hwu <fit...@gmail.com> wrote:
I have a main activity that extends IOIOActivity. Within this main activity I have function called scan(), which calls startActivityForResult() to open up a new activity to scan a QR code using the Android phone. The usual life cycle for main activity in this case is to pause, stop, let the QR activity scan, start, then resume. Accordingly, I think the 

IOIOAndroidApplicationHelper should reestablish the IOIO connection at the start stage. However, this doesn't happen and the IOIO connection is gone when the main activity resumes. Any ideas on why this is happening? I can post some code if more clarity is needed. Thanks!

--
You received this message because you are subscribed to the Google Groups "ioio-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ioio-users+...@googlegroups.com.
To post to this group, send email to ioio-...@googlegroups.com.
Visit this group at http://groups.google.com/group/ioio-users.
For more options, visit https://groups.google.com/d/optout.

hwut

unread,
May 19, 2015, 5:51:29 PM5/19/15
to ioio-...@googlegroups.com
Sure, here is a log of the case that causes the problem:

05-19 14:15:08.018: I/abr.main(17259): scan() called
05-19 14:15:08.038: I/abr.main(17259): main activity pausing
05-19 14:15:09.828: I/abr.main(17259): main activity stopping
05-19 14:15:09.828: I/AndroidApplicationHelper(17259): AndroidApplicationHelper stop()
05-19 14:15:09.838: I/IOIO_thread(17259): IOIO_thread disconnected
05-19 14:15:09.838: I/AndroidIOIOConnectionManager(17259): AndroidIOIOConnectionManager stop()
05-19 14:15:14.068: I/abr.main(17259): main activity restarting
05-19 14:15:14.068: I/abr.main(17259): main activity starting
05-19 14:15:14.068: I/AndroidApplicationHelper(17259): AndroidApplicationHelper start()
05-19 14:15:14.068: I/AndroidIOIOConnectionManager(17259): AndroidIOIOConnectionManager start()
05-19 14:15:14.068: I/abr.main(17259): main activity resuming

Occasionally, when starting the new activity, the main activity will be destroyed. In this case the IOIO connection does come back.

05-19 14:45:19.398: I/abr.main(2984): scan() called
05-19 14:45:19.438: I/abr.main(2984): main activity pausing
05-19 14:45:20.318: I/abr.main(2984): main activity stopping
05-19 14:45:20.318: I/AndroidApplicationHelper(2984): AndroidApplicationHelper stop()
05-19 14:45:20.328: I/IOIO_thread(2984): IOIO_thread disconnected
05-19 14:45:20.328: I/AndroidIOIOConnectionManager(2984): AndroidIOIOConnectionManager stop()
05-19 14:45:25.868: I/abr.main(2984): main activity being destroyed
05-19 14:45:25.868: I/AndroidApplicationHelper(2984): AndroidApplicationHelper destroy()
05-19 14:45:25.868: I/AndroidIOIOConnectionManager(2984): AndroidIOIOConnectionManager destroy()
05-19 14:45:25.898: I/abr.main(2984): main activity being created
05-19 14:45:25.958: I/AndroidApplicationHelper(2984): AndroidApplicationHelper create()
05-19 14:45:25.958: I/AndroidIOIOConnectionManager(2984): AndroidIOIOConnectionManager create()
05-19 14:45:25.968: I/abr.main(2984): main activity starting
05-19 14:45:25.968: I/AndroidApplicationHelper(2984): AndroidApplicationHelper start()
05-19 14:45:25.968: I/AndroidIOIOConnectionManager(2984): AndroidIOIOConnectionManager start()
05-19 14:45:25.978: I/abr.main(2984): main activity resuming
05-19 14:45:25.988: I/abr.main(2984): main activity pausing
05-19 14:45:26.018: I/abr.main(2984): main activity resuming

Ytai Ben-Tsvi

unread,
May 19, 2015, 6:01:29 PM5/19/15
to ioio-...@googlegroups.com

You seem to have omitted the logs generated by IOIOLib itself. Can you include them? Which version of the library is this? What type of connection are you using between the Android and IOIO?

hwut

unread,
May 20, 2015, 8:34:39 PM5/20/15
to ioio-...@googlegroups.com
Sorry, I see what you mean about the IOIOLib logs now. I'm using the most recent version, version 5, and a bluetooth connection between the Android and IOIO.

Here is the log when I first open the app. All "blar" tags are my own generated tags.

05-20 17:27:21.921: D/IOIOConnectionRegistry(23052): Successfully added bootstrap class: ioio.lib.impl.SocketIOIOConnectionBootstrap
05-20 17:27:21.921: D/IOIOConnectionRegistry(23052): Bootstrap class not found: ioio.lib.android.accessory.AccessoryConnectionBootstrap. Not adding.
05-20 17:27:21.931: D/IOIOConnectionRegistry(23052): Successfully added bootstrap class: ioio.lib.android.bluetooth.BluetoothIOIOConnectionBootstrap
05-20 17:27:21.931: D/IOIOConnectionRegistry(23052): Bootstrap class not found: ioio.lib.android.device.DeviceConnectionBootstrap. Not adding.
05-20 17:27:21.951: I/blar(23052): main activity being created
05-20 17:27:22.021: I/blar(23052): AndroidApplicationHelper create()
05-20 17:27:22.021: I/blar(23052): AndroidIOIOConnectionManager create()
05-20 17:27:22.031: I/blar(23052): main activity starting
05-20 17:27:22.031: I/blar(23052): AndroidApplicationHelper start()
05-20 17:27:22.031: I/blar(23052): AndroidIOIOConnectionManager start()
05-20 17:27:22.041: I/blar(23052): main activity resuming
05-20 17:27:22.051: D/IOIOImpl(23052): Waiting for IOIO connection
05-20 17:27:22.051: V/IOIOImpl(23052): Waiting for underlying connection
05-20 17:27:22.071: V/BluetoothIOIOConnection(23052): Attempting to connect to Bluetooth device: IOIO (5C:82)
05-20 17:27:23.131: V/BluetoothIOIOConnection(23052): Established connection to device IOIO (5C:82) address: 00:1B:DC:06:5C:82
05-20 17:27:23.131: V/IOIOImpl(23052): Waiting for handshake
05-20 17:27:23.131: V/IOIOImpl(23052): Querying for required interface ID
05-20 17:27:23.141: V/IOIOImpl(23052): Required interface ID is supported
05-20 17:27:23.141: I/IOIOImpl(23052): IOIO connection established

This is what happens when scan() is called, and reconnection of the IOIO is successful. The main activity had been destroyed and recreated.

05-20 17:27:27.671: I/blar(23052): scan() called
05-20 17:27:27.701: I/blar(23052): main activity pausing
05-20 17:27:28.531: I/blar(23052): main activity stopping
05-20 17:27:28.531: I/blar(23052): AndroidApplicationHelper stop()
05-20 17:27:28.531: D/IOIOImpl(23052): Client requested disconnect.
05-20 17:27:28.531: V/BluetoothIOIOConnection(23052): Client initiated disconnect
05-20 17:27:28.531: D/IOIOImpl(23052): Client requested disconnect.
05-20 17:27:28.531: I/IOIOProtocol(23052): IOIO disconnected
05-20 17:27:28.531: I/blar(23052): IOIO_thread disconnected
05-20 17:27:28.541: D/IOIOBaseApplicationHelper(23052): IOIOThread is exiting
05-20 17:27:28.541: I/blar(23052): AndroidIOIOConnectionManager stop()
05-20 17:27:34.171: I/blar(23052): main activity being destroyed
05-20 17:27:34.171: I/blar(23052): AndroidApplicationHelper destroy()
05-20 17:27:34.171: I/blar(23052): AndroidIOIOConnectionManager destroy()
05-20 17:27:34.191: I/blar(23052): main activity being created
05-20 17:27:34.221: I/blar(23052): AndroidApplicationHelper create()
05-20 17:27:34.221: I/blar(23052): AndroidIOIOConnectionManager create()
05-20 17:27:34.231: I/blar(23052): main activity starting
05-20 17:27:34.231: I/blar(23052): AndroidApplicationHelper start()
05-20 17:27:34.231: I/blar(23052): AndroidIOIOConnectionManager start()
05-20 17:27:34.251: D/IOIOImpl(23052): Waiting for IOIO connection
05-20 17:27:34.251: V/IOIOImpl(23052): Waiting for underlying connection
05-20 17:27:34.251: V/BluetoothIOIOConnection(23052): Attempting to connect to Bluetooth device: IOIO (5C:82)
05-20 17:27:34.271: I/blar(23052): main activity resuming
05-20 17:27:34.521: V/BluetoothIOIOConnection(23052): Established connection to device IOIO (5C:82) address: 00:1B:DC:06:5C:82
05-20 17:27:34.521: V/IOIOImpl(23052): Waiting for handshake
05-20 17:27:34.521: V/IOIOImpl(23052): Querying for required interface ID
05-20 17:27:34.531: V/IOIOImpl(23052): Required interface ID is supported
05-20 17:27:34.541: I/IOIOImpl(23052): IOIO connection established

This is what happens when the reconnection doesn't work:

05-20 17:27:47.001: I/blar(23052): scan() called
05-20 17:27:47.031: I/blar(23052): main activity pausing
05-20 17:27:48.811: I/blar(23052): main activity stopping
05-20 17:27:48.811: I/blar(23052): AndroidApplicationHelper stop()
05-20 17:27:48.811: D/IOIOImpl(23052): Client requested disconnect.
05-20 17:27:48.811: V/BluetoothIOIOConnection(23052): Client initiated disconnect
05-20 17:27:48.821: I/IOIOProtocol(23052): IOIO disconnected
05-20 17:27:48.821: I/blar(23052): IOIO_thread disconnected
05-20 17:27:48.821: D/IOIOBaseApplicationHelper(23052): IOIOThread is exiting
05-20 17:27:48.821: I/blar(23052): AndroidIOIOConnectionManager stop()
05-20 17:27:53.021: I/blar(23052): main activity restarting
05-20 17:27:53.021: I/blar(23052): main activity starting
05-20 17:27:53.021: I/blar(23052): AndroidApplicationHelper start()
05-20 17:27:53.021: I/blar(23052): AndroidIOIOConnectionManager start()
05-20 17:27:53.031: I/blar(23052): main activity resuming

Ytai Ben-Tsvi

unread,
May 21, 2015, 1:30:40 PM5/21/15
to ioio-...@googlegroups.com
The method that emits the "main activity restarting": what's actually happening there? Is it possible that some event that needs to propagate to the IOIO framework doesn't make it through? Looks like the destroy()/create() sequence is what makes things work. Can you debug a little and figure out what is it that they do that makes a difference?

hwut

unread,
May 21, 2015, 10:18:49 PM5/21/15
to ioio-...@googlegroups.com
Hm, I'm still not figuring out the cause of the issue. I'd assume that helper_.start() in the IOIOActivity onStart() should get the Bluetooth connection back, but it doesn't. Whether the main app gets destroyed/created seems to be an arbitrary thing that the Android OS takes care of, perhaps to clear up memory. I'm working around the problem by forcing the app to quit and restart after the end of a scan(), and keeping the relevant state by passing variables through an Intent. This is the quickest solution for now and works fine for me, but I will try to do some more debugging later and post if I find a solution.

Ytai Ben-Tsvi

unread,
May 22, 2015, 5:59:21 PM5/22/15
to ioio-...@googlegroups.com
I'm aware that whether to destroy an activity is at the discretion of the OS. From the examples you posted it seems like it might be what's making the difference between being able to reconnect and not being able to reconnect. If that's indeed the case, I'm wondering what effect the destroy/create has on the IOIO-related software that makes it close the connection more cleanly.
Reply all
Reply to author
Forward
0 new messages