How to stop tracking location?
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 |
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 |
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 '18 at 18:49
Federico Grandi
2,70021127
2,70021127
asked Nov 19 '18 at 15:42
Sireesha Devineni
1
1
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
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 |
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 |
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 |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
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
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
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 |
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 |
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 '18 at 15:54
Bonatti
2,37341533
2,37341533
add a comment |
add a comment |
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 |
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 |
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 '18 at 16:09
Mahabub Karim
212
212
add a comment |
add a comment |
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 |
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 |
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 '18 at 16:10
answered Nov 19 '18 at 16:01
Kay Tukendorf
65
65
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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