[Android Q&A, Help & Troubleshooting] Spanners_:
Hi everyone

I'm fairly sure this is the right place to put this, but please correct me if I'm wrong.

I'm trying to create an app that take GPS coordinates from the inbuilt system and output it via an IOIO board (just a board that allows the phone to have digital and analogue output) so that it can be transmitted via a separate module to a receiver. The system will then be used to track a balloon.

I made some headway, I can send "Hello World" easily, but simply can't make the LocationManager work for me as using that just stops everything from working. My Java skills leave a lot to be desired, so I was hoping someone could check over my code and look for a fundamental mistake. The problem appears LocationUpdateHandler class, as relying on that to generate the 'stuff' variable simply halts the entire program.

It is based on two pieces of sample code that came with the IOIO board, but the GPS part is my own.

package ioio.examples.hello;

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.content.Context;
import android.os.Bundle;
import android.widget.ToggleButton;
import ioio.lib.api.Uart;
import java.io.OutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;

/**
* 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.
*/
public class MainActivity extends IOIOActivity {
private ToggleButton button_;
private LocationManager locationManager;
String provider;
String stuff;

/**
* Called when the activity is first created. Here we normally initialize
* our GUI.
*/
[MENTION=439709]override[/MENTION]
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
button_ = (ToggleButton) findViewById(R.id.button);

//Sets up the location manager and listener. I feel this section is the root of my problems
LocationListener locationListener = new LocationUpdateHandler();
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 35000, 10, new LocationUpdateHandler());
}

//Should, in theory, set the global variable 'stuff' to be the location of the phone stored as a string
public class LocationUpdateHandler implements LocationListener {

public void onLocationChanged(Location loc) {
double lat = loc.getLatitude();
double lng = loc.getLongitude();
stuff = Double.toString(lat) + "$" + Double.toString(lng) + "&";
}
[MENTION=439709]override[/MENTION]
public void onProviderDisabled(String provider) {}

[MENTION=439709]override[/MENTION]
public void onProviderEnabled(String provider) {}

[MENTION=439709]override[/MENTION]
public void onStatusChanged(String provider, int status,
Bundle extras) {}
}

/**
* 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_;

Uart uart;
OutputStream outGPS;

/**
* Called every time a connection with IOIO has been established.
* Typically used to open pins.
*
* [MENTION=948141]Throw[/MENTION]s ConnectionLostException
* When IOIO connection is lost.
*
* [MENTION=690402]see[/MENTION] ioio.lib.util.AbstractIOIOActivity.IOIOThread#setup()
*/
[MENTION=439709]override[/MENTION]
public void setup() throws ConnectionLostException {
led_ = ioio_.openDigitalOutput(0, true);
uart = ioio_.openUart(3,4, 9600, Uart.Parity.NONE, Uart.StopBits.ONE);
outGPS = uart.getOutputStream();
}

public void loop() throws ConnectionLostException {
led_.write(!button_.isChecked());
byte[] GPSCoordinate = null;
//If I set stuff to "Hello World" here the IOIO board succesfully transmits hello world
try {
GPSCoordinate = stuff.getBytes("US-ASCII");
} catch (UnsupportedEncodingException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}

try {
outGPS.write(GPSCoordinate);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}

}
[MENTION=439709]override[/MENTION]
protected IOIOLooper createIOIOLooper() {
return new Looper();
}
}

Thank you for your help,

Spanners.