I have an activity that updates the display with the result of code in the onLocationChanged in the location listener. Everything works fine but I want to exit to another activity after a certain amount of time.
I tried inserting the same code I use in a menu to switch activities in the location listener but it won’t work. I get an error.
if (dTime < -30){
Intent target1 = new Intent(this, Waypoint2.class);
startActivity(target1);
}
Does anyone know how to do this. Searches of Google and stackoverflow came up empty.
UPDATE:
The problem seems to be a combination of what was solved by Jeet and the fact that I was leaving the location manager mid task. The finish(); statement would execute the stop code and changing the code to this also worked and is clearer for anyone having this problem.
if (dTime < -30){
//finish();
if(lm != null) {
lm.removeUpdates(ll);
}
ll = null;
lm = null;
Intent target = new Intent(Start2.this, Waypoint2.class);
startActivity(target);
}
The code between the //finish(); and Intent is what is in the onStop section.
Error might be, method Intent(LocationListener, Class) is undefined, so you need to replace it by:
where context is the Context of the Activity, you can get Context of the Activity by Explicitly passing in Constructor, or YourActivityName.this, if LocationListener is implemented in the same file, as your activity.