How to stop tracking location?
up vote
0
down vote
favorite
I have a location-based alerting app when a user enters near to particular area, he/she should be alerted. I need to stop tracking location after the alert is clicked once. But my app is continuously alerting the user. How to stop it?
I included code to check the distance between the user current location and destination in location onChange
method.
public void onLocationChanged(Location location) {
double lat1 = location.getLatitude();
double lon1 = location.getLongitude();
checkloc(lat1, lon1);
}
android android-studio location locationmanager
add a comment |
up vote
0
down vote
favorite
I have a location-based alerting app when a user enters near to particular area, he/she should be alerted. I need to stop tracking location after the alert is clicked once. But my app is continuously alerting the user. How to stop it?
I included code to check the distance between the user current location and destination in location onChange
method.
public void onLocationChanged(Location location) {
double lat1 = location.getLatitude();
double lon1 = location.getLongitude();
checkloc(lat1, lon1);
}
android android-studio location locationmanager
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have a location-based alerting app when a user enters near to particular area, he/she should be alerted. I need to stop tracking location after the alert is clicked once. But my app is continuously alerting the user. How to stop it?
I included code to check the distance between the user current location and destination in location onChange
method.
public void onLocationChanged(Location location) {
double lat1 = location.getLatitude();
double lon1 = location.getLongitude();
checkloc(lat1, lon1);
}
android android-studio location locationmanager
I have a location-based alerting app when a user enters near to particular area, he/she should be alerted. I need to stop tracking location after the alert is clicked once. But my app is continuously alerting the user. How to stop it?
I included code to check the distance between the user current location and destination in location onChange
method.
public void onLocationChanged(Location location) {
double lat1 = location.getLatitude();
double lon1 = location.getLongitude();
checkloc(lat1, lon1);
}
android android-studio location locationmanager
android android-studio location locationmanager
edited Nov 19 at 18:49
Federico Grandi
2,3531925
2,3531925
asked Nov 19 at 15:42
Sireesha Devineni
1
1
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
up vote
0
down vote
You might want to have a Flag, representing if the user was already warned, for instance:
boolean WAS_WAARNED = false;
void onLocationChanged(Location location) {
if(!WAS_WARNED){
WAS_WARNED = true;
checkloc(location.getLatitude(), location.getLongitude());
}
}
add a comment |
up vote
0
down vote
First Approach->
Save alert clicked the flag to PrefUtils which is the most useable memory for save status. When a user clicks the alert you just set the status true and save it to prefUtils.
public void onLocationChanged(Location location) {
if(PrefUtils.getLoationStatus(getApplicationContext(), false)) {
double lat1=location.getLatitude();
double lon1=location.getLongitude();
checkloc(lat1,lon1);
PrefUtils.setLocationStatus(true);
}
}
Second Approach ->
When the alert is clicked just set -> locationManager.removeUpdates(this);
add a comment |
up vote
0
down vote
You'll want to stop requesting location updates. This can be done by calling removeLocationUpdates on your location client.
For example:
alertButton.setOnClickListener(view -> {
//Do some stuff.
if (mLocationClient != null){
mLocationClient.removeLocationUpdates(mLocationCallback)}
});
Here, mLocationClient is your FusedLocationProviderClient, and mLocationCallback is your LocationCallback (this will have the onLocationChanged method within it). Since you check their location in the onLocationChanged method, there will no longer be updates to the location so the alert won't be created. You could also call removeLocationUpdates in your checkloc method if they are in the correct location.
Here is a link to the documentation for the FusedLocationProviderClient, giving more information.
Note: you may want to look up geofencing. It does something similar to what you want to do.
add a comment |
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
You might want to have a Flag, representing if the user was already warned, for instance:
boolean WAS_WAARNED = false;
void onLocationChanged(Location location) {
if(!WAS_WARNED){
WAS_WARNED = true;
checkloc(location.getLatitude(), location.getLongitude());
}
}
add a comment |
up vote
0
down vote
You might want to have a Flag, representing if the user was already warned, for instance:
boolean WAS_WAARNED = false;
void onLocationChanged(Location location) {
if(!WAS_WARNED){
WAS_WARNED = true;
checkloc(location.getLatitude(), location.getLongitude());
}
}
add a comment |
up vote
0
down vote
up vote
0
down vote
You might want to have a Flag, representing if the user was already warned, for instance:
boolean WAS_WAARNED = false;
void onLocationChanged(Location location) {
if(!WAS_WARNED){
WAS_WARNED = true;
checkloc(location.getLatitude(), location.getLongitude());
}
}
You might want to have a Flag, representing if the user was already warned, for instance:
boolean WAS_WAARNED = false;
void onLocationChanged(Location location) {
if(!WAS_WARNED){
WAS_WARNED = true;
checkloc(location.getLatitude(), location.getLongitude());
}
}
answered Nov 19 at 15:54
Bonatti
2,37441533
2,37441533
add a comment |
add a comment |
up vote
0
down vote
First Approach->
Save alert clicked the flag to PrefUtils which is the most useable memory for save status. When a user clicks the alert you just set the status true and save it to prefUtils.
public void onLocationChanged(Location location) {
if(PrefUtils.getLoationStatus(getApplicationContext(), false)) {
double lat1=location.getLatitude();
double lon1=location.getLongitude();
checkloc(lat1,lon1);
PrefUtils.setLocationStatus(true);
}
}
Second Approach ->
When the alert is clicked just set -> locationManager.removeUpdates(this);
add a comment |
up vote
0
down vote
First Approach->
Save alert clicked the flag to PrefUtils which is the most useable memory for save status. When a user clicks the alert you just set the status true and save it to prefUtils.
public void onLocationChanged(Location location) {
if(PrefUtils.getLoationStatus(getApplicationContext(), false)) {
double lat1=location.getLatitude();
double lon1=location.getLongitude();
checkloc(lat1,lon1);
PrefUtils.setLocationStatus(true);
}
}
Second Approach ->
When the alert is clicked just set -> locationManager.removeUpdates(this);
add a comment |
up vote
0
down vote
up vote
0
down vote
First Approach->
Save alert clicked the flag to PrefUtils which is the most useable memory for save status. When a user clicks the alert you just set the status true and save it to prefUtils.
public void onLocationChanged(Location location) {
if(PrefUtils.getLoationStatus(getApplicationContext(), false)) {
double lat1=location.getLatitude();
double lon1=location.getLongitude();
checkloc(lat1,lon1);
PrefUtils.setLocationStatus(true);
}
}
Second Approach ->
When the alert is clicked just set -> locationManager.removeUpdates(this);
First Approach->
Save alert clicked the flag to PrefUtils which is the most useable memory for save status. When a user clicks the alert you just set the status true and save it to prefUtils.
public void onLocationChanged(Location location) {
if(PrefUtils.getLoationStatus(getApplicationContext(), false)) {
double lat1=location.getLatitude();
double lon1=location.getLongitude();
checkloc(lat1,lon1);
PrefUtils.setLocationStatus(true);
}
}
Second Approach ->
When the alert is clicked just set -> locationManager.removeUpdates(this);
answered Nov 19 at 16:09
Mahabub Karim
11
11
add a comment |
add a comment |
up vote
0
down vote
You'll want to stop requesting location updates. This can be done by calling removeLocationUpdates on your location client.
For example:
alertButton.setOnClickListener(view -> {
//Do some stuff.
if (mLocationClient != null){
mLocationClient.removeLocationUpdates(mLocationCallback)}
});
Here, mLocationClient is your FusedLocationProviderClient, and mLocationCallback is your LocationCallback (this will have the onLocationChanged method within it). Since you check their location in the onLocationChanged method, there will no longer be updates to the location so the alert won't be created. You could also call removeLocationUpdates in your checkloc method if they are in the correct location.
Here is a link to the documentation for the FusedLocationProviderClient, giving more information.
Note: you may want to look up geofencing. It does something similar to what you want to do.
add a comment |
up vote
0
down vote
You'll want to stop requesting location updates. This can be done by calling removeLocationUpdates on your location client.
For example:
alertButton.setOnClickListener(view -> {
//Do some stuff.
if (mLocationClient != null){
mLocationClient.removeLocationUpdates(mLocationCallback)}
});
Here, mLocationClient is your FusedLocationProviderClient, and mLocationCallback is your LocationCallback (this will have the onLocationChanged method within it). Since you check their location in the onLocationChanged method, there will no longer be updates to the location so the alert won't be created. You could also call removeLocationUpdates in your checkloc method if they are in the correct location.
Here is a link to the documentation for the FusedLocationProviderClient, giving more information.
Note: you may want to look up geofencing. It does something similar to what you want to do.
add a comment |
up vote
0
down vote
up vote
0
down vote
You'll want to stop requesting location updates. This can be done by calling removeLocationUpdates on your location client.
For example:
alertButton.setOnClickListener(view -> {
//Do some stuff.
if (mLocationClient != null){
mLocationClient.removeLocationUpdates(mLocationCallback)}
});
Here, mLocationClient is your FusedLocationProviderClient, and mLocationCallback is your LocationCallback (this will have the onLocationChanged method within it). Since you check their location in the onLocationChanged method, there will no longer be updates to the location so the alert won't be created. You could also call removeLocationUpdates in your checkloc method if they are in the correct location.
Here is a link to the documentation for the FusedLocationProviderClient, giving more information.
Note: you may want to look up geofencing. It does something similar to what you want to do.
You'll want to stop requesting location updates. This can be done by calling removeLocationUpdates on your location client.
For example:
alertButton.setOnClickListener(view -> {
//Do some stuff.
if (mLocationClient != null){
mLocationClient.removeLocationUpdates(mLocationCallback)}
});
Here, mLocationClient is your FusedLocationProviderClient, and mLocationCallback is your LocationCallback (this will have the onLocationChanged method within it). Since you check their location in the onLocationChanged method, there will no longer be updates to the location so the alert won't be created. You could also call removeLocationUpdates in your checkloc method if they are in the correct location.
Here is a link to the documentation for the FusedLocationProviderClient, giving more information.
Note: you may want to look up geofencing. It does something similar to what you want to do.
edited Nov 19 at 16:10
answered Nov 19 at 16:01
Kay Tukendorf
65
65
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53378128%2fhow-to-stop-tracking-location%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown