I have three activities A, B, C. A is my menu, upon button click it starts Activity B, in activity B, based on the outcome of an if statement Activity C is started.
The problem is C runs, the processes can be see in the logcat but doesn't open. B continues to play the alarm and vibrate and then the phone stalls and the alarm and vibrate continue. I have the code for the if statement above and the code for the openMaps() function as well, this is called based on the outcome of the if, in which I try to open Activity C and close B
EDIT
I have changed my code somewhat, ok, I have an idea what the problem is, I just don't know how to solve it. I have a thread, inside that thread is an infinate while loop, inside this infinite while loop I check the distance between two coordinates (i want them constantly updating).
The problem is, variables I have declared globally are initialized within the loop so I have to run my if statement within that, to access those...I tried using a boolean 'test' that if it's true execute the if statement then set test to false but that doesn't work I'm afraid.
Thread dist = new Thread(new Runnable() {
public void run() {
while (true) {
child = new Location("point A");
child.setLatitude(Clatitude);
child.setLongitude(Clongitude);
parent = new Location("point B");
parent.setLatitude(Platitude);
parent.setLongitude(Plongitude);
distance = child.distanceTo(parent);
DisRound = 550;
dynamicActivation = DisRound * weight;
try {
Thread.sleep(1000);
if (test)
{
if(dynamicActivation > threshold)
{
finish();
new Timer().schedule(new MapsTimer(), 5000);
test = false;
}
Log.d("ACTIVATION", Boolean.toString(test));
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
});
dist.start();
Here is the code for my MapsTimer that i'm calling in the if statement
private class MapsTimer extends TimerTask {
@Override
public void run() {
runOnUiThread(new Runnable() {
public void run() {
int duration = Toast.LENGTH_SHORT;
CharSequence text = "YOUR CHILD HAS TRAVELLED OUTSIDE PROXIMITY";
Context context = getApplicationContext();
proximityAlert = Toast.makeText(context, text, duration);
proximityAlert.show();
alarmSound.start();
openMaps();
}
});
}
So, distance, DisRound and dynamicActivation are all global but initialized in the infinite loop, if I can access these outside this loop, I'm sure I can stop the problem. Anyone have any thoughts?
Regards,
Gary