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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:17:05+00:00 2026-06-17T12:17:05+00:00

I have a handler for receiving SMS in a seperate class. How can I

  • 0

I have a handler for receiving SMS in a seperate class. How can I make it change the view elements when the handler is executed?

Here is my code:

public class MainActivity extends MapActivity {
    MapView mapView;
    MapController mc;
    GeoPoint p;
    private int carNumber;
    private String langt;
    private String longt;
    CheckedTextView text;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        SmsReceiver smsreceiver = new SmsReceiver();
                draw();
    }

    public void draw() {
        mapView = (MapView) findViewById(R.id.mapView);
        LinearLayout zoomLayout = (LinearLayout) findViewById(R.id.zoom);
        @SuppressWarnings("deprecation")
        View zoomView = mapView.getZoomControls();

        zoomLayout.addView(zoomView, new LinearLayout.LayoutParams(
            LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
        mapView.displayZoomControls(true);
        mc = mapView.getController();

        double lat = Double.parseDouble("31.977185185185185");
        double lng = Double.parseDouble("35.205925925925925");

        p = new GeoPoint((int) (lat * 1E6), (int) (lng * 1E6));

        mc.animateTo(p);
        mc.setZoom(17);
        MapOverlay mapOverlay = new MapOverlay();
        List<Overlay> listOfOverlays = mapView.getOverlays();
        listOfOverlays.clear();
        listOfOverlays.add(mapOverlay);

        mapView.invalidate();
    }
}
}

Here is the SMS Receiver class:

public class SmsReceiver extends BroadcastReceiver {
    MapView mapView;
    MapController mc;
    GeoPoint p;
    private int carNumber;
    private String langt;
    private String longt;
    CheckedTextView text;

    public SmsReceiver(MapView mapView) {
        this.mapView = mapView;
    }
    private static final String SMS_RECEIVED = "android.provider.Telephony.SMS_RECEIVED";

    @SuppressLint("NewApi") @Override
    public void onReceive(final Context context, final Intent intent) {
        if (intent != null && SMS_RECEIVED.equals(intent.getAction())) {
            final SmsMessage smsMessage = extractSmsMessage(intent);
            processMessage(context, smsMessage);
        }
    }

    @SuppressLint("NewApi") private SmsMessage extractSmsMessage(final Intent intent) {
        final Bundle pudsBundle = intent.getExtras();
        final Object[] pdus = (Object[]) pudsBundle.get("pdus");
        final SmsMessage smsMessage = SmsMessage.createFromPdu((byte[]) pdus[0]);

        return smsMessage;
     }
}

I want to modify the MapView inside the SmsReceiver class.

Thank you.

  • 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-17T12:17:05+00:00Added an answer on June 17, 2026 at 12:17 pm

    Define an interface and use a callback to let the activity know that an SMS has been received.

    public Interface SmsReceivedListener {
        void onSmsReceived(int arg1, string arg2); ..<----add arguments you want to pass back
    }
    

    In your SMS class

    ArrayList<SmsReceivedistener> listeners = new ArrayList<SmsReceivedistener>();
    
    ...
    
    public void setSmsReceivedistener(SmsReceivedistenerlistener){
        listeners.add(listener);
    }
    

    When you receive an SMS

    for (SmsReceivedistener listener:listeners){
       listener.onSmsReceived(arg1, arg2);
    }
    

    In your Activity:

    public class MainActivity extends MapActivity implements SmsReceivedListener {
    
    ...
    
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        ...
        smsReceiver.setSmsReceivedistener(this);
        ...
    }
    
    public void onSmsReceived(int arg1, string arg2){
       // do whatever you need to do
    }
    

    All from memory so please excuse typos and you should improve the SMS class by adding removeSmsReceivedistener and checking that you do not add the same listener twice in setSmsReceivedistener.

    Note. Because you use an interface, any class (not just an Activity) can implement it so you can update anywhere in your app. The smsReceiver class doesn’t know or care. It just calls the listeners, if any are registered.

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

Sidebar

Related Questions

I have a Handler class that looks like this: class Handler{ public $group; public
I have a handler, like this, using IRequiresSessionState: public class MyHandler : IHttpHandler, IRequiresSessionState
I have an event handler that needs to determine a type and execute code
I have an App that has a thread handler receiving some socket data all
I have following ContentObserver implementation for receiving and writing SMS, but it is called
I have a Network Client class that is receiving a large binary block and
I have a handler and I have to send responses to different activities for
I have a handler and a runnable, Handler has a loop that runs from
We have a requirment which requires to have an Handler that is extended from
In my APP. Need to use Lazy Loading, so I have to handler the

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.