Android: (if) not working properly
I am trying to set one message in toast. My idea is when the GPS is turn
on and the Latitude and Longitude is not "0" then to receive message like
this "gps is connected to satellites". But it's look this method is not
working. If I say to if- GPS turn off or the Latitude and Longitude is
equals to "0" then everything work properly. Just whyyy! I dont't get it.
Here is the code
Thanks in advance.
LocationListener Loclist = new LocationListener(){
@Override
public void onLocationChanged(Location lc){
// TODO Auto-generated method stub
//not working but with right logic
//GPS is turn on and the Latitude and Longitude is not "0"
if(lc != null && lastLat != 0 && lastLon != 0){
Context context = getApplicationContext();
CharSequence text = "GPS is connected to satellites.";
int duration = Toast.LENGTH_LONG;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
}
//working but with wrong logic
//GPS turn off or the Latitude and Longitude is equals to "0"
if(lc == null || lastLat == 0 && lastLon == 0){
Context context = getApplicationContext();
CharSequence text = "GPS is connected to satellites.";
int duration = Toast.LENGTH_LONG;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
}
}
No comments:
Post a Comment