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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:10:49+00:00 2026-05-31T17:10:49+00:00

I’m trying to add an overlay to a MapView from a background thread to

  • 0

I’m trying to add an overlay to a MapView from a background thread to optically mark the point the user is currently touching.

At the moment I try to achieve that using Timer/Handler.
When the MotionEvent is ACTION_DOWN, I post a task, which adds the circle overlay to the mapView overlays after a certain delay.

Unfortunately, the UI is only updated after the user removes the finger from the screen (ACTION_UP).

Here’s the sample code:

UI thread

if (event.getAction() == MotionEvent.ACTION_DOWN) {
    handler = new OverlayHandler(mapView, centerDrawer) // centerDrawer is an overlay drawing a circle
    cTask = new DrawTimer(handler); // Calls handler.sendMessage, telling the handler to add centerDraw to the overlays of mapView

    handler.postDelayed(cTast, delay);

} else {
    handler.removeCallbacks(cTask);
}

Timer (DrawTimer etc.)

public void run() {
    Message msg = new Message();
    msg.what = 1;
    handler.sendMessage(msg);
}

Handler

public void handleMessage(Message msg) {
    switch (msg.what) {
    case 1:
            mapView.getOverlays().add(centerDrawer);
    break;
        // more cases
    }
    super.handleMessage(msg);
}

As far as I know, this is the default way to interact with the UI from a background task.

Is this also valid for updates while the user is interacting with the screen?
Do I have to explicitly tell the view to render new overlays?

EDIT:

The code should do the following:
On touch, it should start to observe how long the user keeps touching. After an inital delay, the circle should be added to the view. After some more delay, another overlay is added and so forth.

I do that for each overlay in two steps:
I add a Runnable to handler to be executed after a delay. The Runnable then sends the corresponding message to the handler, telling it, what to draw.
I’m doing it like that, because…

  • I need to be able to cancel the timer (the post), if the user moves or releases its finger.
  • Some overlays should change, when the user keeps touching the screen. The postDelayed Runnable just keeps sending messages till canceled.

That’s why I don’t just use delayed messages.

Use cases

  • User touches screen -> user releases before delay passes (nothing should appear)

  • Touch -> delay passes -> circle -> release

  • Touch -> delay passes -> circle -> delay 2 passes -> circle 2 -> release

  • 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-31T17:10:50+00:00Added an answer on May 31, 2026 at 5:10 pm

    Found the answer in this question:
    Views Don't Update Until MapView is Touched

    mapView.invalidate() forces the view to redraw all its overlays. It might not be the most efficient way to implement that behavior but it works the way I want it to.

    Thanks to farble1670 for pointing at some problems with my prior implementation.
    Following his advice I changed it to use messages only (which are cancelable as well using removeMessage).

    The new code is even simpler:

    UI Thread

    if (event.getAction() == MotionEvent.ACTION_DOWN) {
        handler = new OverlayHandler(mapView, centerDrawer)
    
        handler.sendEmptyMessageDelayed(1, d);
    
    } else {
        handler.removeMessage(1);
    }
    

    Handler

    public void handleMessage(Message msg) {
        switch (msg.what) {
        case 1:
            mapView.getOverlays().add(centerDrawer);
        break;
            // more cases
        }
        mapView.invalidate(); // Forces redrawing of all overlays
        super.handleMessage(msg);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am currently running into a problem where an element is coming back from
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

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.