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 8641953
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:39:38+00:00 2026-06-12T11:39:38+00:00

I want from the class gps_Listener create Intent and send parameters in class LocationChangedReceiver

  • 0

I want from the “class gps_Listener” create “Intent” and send parameters in “class LocationChangedReceiver”

my class gps_Listener

public class gps_Listener implements LocationListener {

        public void onLocationChanged(Location location) {
            // TODO Auto-generated method stub
            send("I found the location");

        }

        public void onProviderDisabled(String provider) {
            // TODO Auto-generated method stub

        }

        public void onProviderEnabled(String provider) {
            // TODO Auto-generated method stub

        }

        public void onStatusChanged(String provider, int status, Bundle extras) {
            // TODO Auto-generated method stub

        }

        public void send(String str) {
            Intent intent = new Intent("logGPS");
            intent.putExtra("Message", str);
            sendBroadcast(intent);   //-  without context does not work

        }


    }

and class LocationChangedReceiver

public class LocationChangedReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        // TODO Auto-generated method stub

    }

}

I do not know how to do, as you can see there is no “Context”

  • 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-06-12T11:39:39+00:00Added an answer on June 12, 2026 at 11:39 am

    You can pass a context to your listener when you create it.
    So you can use it in your send method:

    public class gps_Listener implements LocationListener {
        private Context context;
    
        public gps_Listener(Context context) {
            this.context = context;
        }
    
        ...
    
        public void send(String str) {
            Intent intent = new Intent("com.your.package.YOUR_ACTION");
            intent.putExtra("Message", str);
            context.sendBroadcast(intent);
        }
    }
    

    Create it that way:

    gps_Listener myListener = new gps_Listener(yourContext);
    LocationManager myManager = (LocationManager)getSystemService(LOCATION_SERVICE);
    myManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, myListener);
    

    Remember to register your broadcast receiver in the manifest (you could also un/register dynamically):

    <receiver android:name=".receivers.LocationChangedReceiver" android:enabled="true">
       <intent-filter>
           <action android:name="com.your.package.YOUR_ACTION"></action>
       </intent-filter>
    </receiver>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: public class MyLocationListener implements LocationListener { @Override public void
Here are snippets of my code: private class NoGpsLock implements Runnable { public void
I want to convert from public class Party { public string Type { get;
Let's say I have created two objects from class foo and now want to
I know that in OOP you want every object (from a class) to be
I want to use the BigInteger class from the System.Numerics but if i want
I want to use a function from another class within a new function which
I want to open a file from a Class in C# using a Process,
I want to pass the values from MapOverlay class to another class. I tried
I want to access the property storedValue from the class method popOperandOffStack: , but

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.