Your problem is that UI elements like toast cannot be called inside the
looper thread.
Do it in a separate Runnable UI thread.
On Saturday, July 26, 2014 9:48:41 AM UTC-5, tdg a wrote:
>
> Hi,
> I'm trying to use the IOIO to turn on the built-in LED with an SMS.
> I launch the IOIOActivity with an intent that contains the text message.
> If I uncomment the TOAST at the onResume, It pops a toast with the correct
> text and that means that my intent is OK and arrives to the right place,
> but the LED never turns on :(
> I've added another TOAST at the loop method, right after the write to the
> led, but it never pops.
> The board itself is OK and runs the HelloIOIO app. My app itself runs OK
> and does not crush (it was not that trivial...).
> This is the code, most of it is copied from the HelloIOIO app:
>
> --------------------------------------------------
> package com.example.test;
>
> import ioio.lib.api.DigitalOutput;
> import ioio.lib.api.exception.ConnectionLostException;
> import ioio.lib.util.BaseIOIOLooper;
> import ioio.lib.util.IOIOLooper;
> import ioio.lib.util.android.IOIOActivity;
> import android.annotation.SuppressLint;
> import android.os.Bundle;
> import android.widget.Toast;
>
> /**
> * This is the main activity of the HelloIOIO example application.
> *
> * It displays a toggle button on the screen, which enables control of the
> * on-board LED. This example shows a very simple usage of the IOIO, by
> using
> * the {@link IOIOActivity} class. For a more advanced use case, see the
> * HelloIOIOPower example.
> */
> @SuppressLint("DefaultLocale")
> public class ToggleLED extends IOIOActivity {
>
> String command = "null";
> boolean ledState = false;
>
> @Override
> public void onCreate(Bundle savedInstanceState) {
> super.onCreate(savedInstanceState);
>
> }
>
> @Override
> public void onResume() {
> super.onResume();
> Bundle extra = getIntent().getExtras();
> command = extra.getString("command");
> if (command.toLowerCase().equals("on")) {
> ledState = true;
> }
> if (command.toLowerCase().equals("off")) {
> ledState = false;
> }
> //Toast.makeText(getBaseContext(), String.valueOf(ledState),
> Toast.LENGTH_LONG).show();
> }
>
> /**
> * This is the thread on which all the IOIO activity happens. It will
> be run
> * every time the application is resumed and aborted when it is
> paused. The
> * method setup() will be called right after a connection with the
> IOIO has
> * been established (which might happen several times!). Then, loop()
> will
> * be called repetitively until the IOIO gets disconnected.
> */
> class Looper extends BaseIOIOLooper {
> /** The on-board LED. */
> private DigitalOutput led_;
>
> /**
> * Called every time a connection with IOIO has been established.
> * Typically used to open pins.
> *
> * @throws ConnectionLostException
> * When IOIO connection is lost.
> *
> * @see ioio.lib.util.AbstractIOIOActivity.IOIOThread#setup()
> */
> @Override
> protected void setup() throws ConnectionLostException {
> led_ = ioio_.openDigitalOutput(0, true);
> }
>
> /**
> * Called repetitively while the IOIO is connected.
> *
> * @throws ConnectionLostException
> * When IOIO connection is lost.
> *
> * @see ioio.lib.util.AbstractIOIOActivity.IOIOThread#loop()
> */
> @Override
> public void loop() throws ConnectionLostException {
> led_.write(!ledState);
> Toast.makeText(getBaseContext(), String.valueOf(ledState),
> Toast.LENGTH_LONG).show();
> try {
> Thread.sleep(100);
> } catch (InterruptedException e) {
> }
> }
> }
>
> /**
> * A method to create our IOIO thread.
> *
> * @see ioio.lib.util.AbstractIOIOActivity#createIOIOThread()
> */
> @Override
> protected IOIOLooper createIOIOLooper() {
> return new Looper();
> }
> }
> -------------------------------------------------------
> Any ideas?
> 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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/ioio-users.
For more options, visit https://groups.google.com/d/optout.