The following allows me to have a location activity run and post its results as strings in to a globally accessible form which then allows me to use in the format of creating a context aware URL through another activity…
As you can see the toast uses the global value which allowed me to test they where accessible.
In the Mainactivity….
public void locationCheck() {
MyLocation myLocation = new MyLocation();
// this is the result
myLocation.getLocation(this, locationResult);
}
public LocationResult locationResult = new LocationResult() {
public void gotLocation(final Location location) {
try {
double lat = location.getLatitude();
double lng = location.getLongitude();
double bearing = location.getBearing();
double speed = location.getSpeed();
if (lat != 0.0 && lng != 0.0) {
String sLat;
String sLng;
String sBearing;
String sSpeed;
sLat = Double.toString(lat);
sLng = Double.toString(lng);
sBearing = Double.toString(bearing);
sSpeed = Double.toString(speed);
// send to global vars
Globals.glat = sLat;
Globals.glng = sLng;
Globals.gBearing = sBearing;
Globals.gSpeed = sSpeed;
String gps_location = Globals.glat + " : " + Globals.glng;
@SuppressWarnings("unused")
String gps_location2 = sBearing + " : " + sSpeed;
Toast.makeText(getBaseContext(),
"We got gps location! " + gps_location + "",
Toast.LENGTH_LONG).show();
}
} catch (Exception e) {
}
}
};
In the Globals Activity
// Global Values
// http://stackoverflow.com/questions/3100726/sharing-global-variables-across-activities-problem-when-using-a-webview
// http://stackoverflow.com/questions/708012/android-how-to-declare-global-variables?rq=1
public class Globals {
static String glat;
static String glng;
static String gBearing;
static String gSpeed;
}
solved How to Pull String Result In To Another Class [closed]