0
In my app, I have an activity called "GpsTrackerActivity
" which is constantly calculating the distance travelled by the method onLocationChanged
, of Interface LocationListener
.
My problem is that I need to open a new activity and I want it, while active, to be able to capture in Loop the value of the public variable "distancia
", who is in the activity "GpsTrackerActivity
".
I’ve tried a cycle While infinity to constantly capture the value of the variable "distance", but this way the app blocks! Someone can help me?
public class GpsTrackerActivity extends AppCompatActivity implements OnMapReadyCallback, LocationListener {
public static double distancia;
....
}
Second Activity:
public class SegundaActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
while (true){
double distancia = GpsTrackerActivity.distancia;
Log.i("Tag", "Distância: " + distancia + " Km");
}
}
....
}
regmorais, thank you so much for your help, as your explanation was excellent. I will opt for the second approach.
– Vitor Mendanha
regmorais, I just didn’t notice in the Meulocationmanager class the public configuration Static Meulocationlistener getInstance(){...}? When inserting it into the Class I get an error because of the name Meulocationlistener?
– Vitor Mendanha
@Vitormendanha I’m sorry, I put the wrong name, the right is Meulocationmanager. I’ve already fixed the answer :)
– regmoraes