Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6097709
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:04:29+00:00 2026-05-23T13:04:29+00:00

I’m working on some application that should fetch current location and after device is

  • 0

I’m working on some application that should fetch current location and after device is located in some radius should be shown application with some message.
I have a few questions.
I’m trying to fetch location using

locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000*60*5, 50, locationListener);
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 1000*60*5, 50, locationListener);
addProximityAlert(LAT,LONG);

private void addProximityAlert(double latitude, double longitude) 
        {
            Intent intent = new Intent(this.getApplicationContext(), SOME_CLASS_HERE); 
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); //Does this needed even if apllication/activity is alive?
            PendingIntent proximityIntent = PendingIntent.getActivity(this.getApplicationContext(), 0, intent, Intent.FLAG_ACTIVITY_NEW_TASK); //and does this needed again?
            locationManager.addProximityAlert(latitude, longitude, Radius, 0, proximityIntent);
        }
  1. If I use requestLocationUpdates then GPS is always working. And this is a waste of battery. Maybe there is some way, for example, to pause this for a several minutes? I mean use GPS every 5 minutes for example from one location fetching to next. How to realize this?

  2. If SOME_CLASS_HERE – some activity class, then how I could know if exactly this event called it? Because when ProximityAlert is triggered I need to call some activity’s function as well. How could I do this?


UPD: Now I’m using only Activity (I haven’t Service at all)
I’m trying next:

Intent intent = new Intent(getString(R.string.intent_message_location_fetched));
PendingIntent proximityIntent = PendingIntent.getBroadcast(this, 0, intent, 0);
locationManager.addProximityAlert(LAT, LONG, RADIUS, 0, proximityIntent);

As I understand intent with action R.string.intent_message_location_fetched should be fired after location will be around LAT LONG.

Then I’m trying to create BroadcastReciver class:

public class MyBroadcastReciver extends BroadcastReceiver {
    MyActivity mainActivity;
    public MyBroadcastReciver(MyActivity activity)
    {
        mainActivity = activity;
    }
    @Override
    public void onReceive(Context context, Intent intent) {
        mainActivity.ShowToast("Recived : " + intent.getAction());
    }
}

And register reciver in MyActivity class:

public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);

        myReciver = new MyBroadcastReciver(this);
        IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(getString(R.string.intent_message_location_fetched));
        registerReceiver(myReciver, intentFilter);
...

But nothing happens when I’m in LAT LONG location. What’s wrong?
Maybe I should register reciver in AndroidManifest.xml? But how exactly?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T13:04:29+00:00Added an answer on May 23, 2026 at 1:04 pm

    1.You should check the answer here for using a timer to turn on / off the location lookups via GPS : android locationManager requestLocationUpdates

    It will start a timer every X seconds. During the processing of the timer, locations updates will be requested, and after a location is retrieved, it will stop the GPS listener.

    2.You should send an intent after your proximity alert logic is over. You can then register a broadcast receiver that listens for that intent, and do your processing. The Intent mechanism provides a loosely coupled way of communicating between activities/services.

    You can find an example of how an intent is broadcast (in your case from your proximity alert) to a broadcastreceiver (a new component in your application that will receive the intent, and process it accordingly). It also shows how to setup the receiver in the manifest to listen for your custom Intent.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.