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

The Archive Base Latest Questions

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

i am programing something in android, and i want to create a delay. when

  • 0

i am programing something in android, and i want to create a delay.
when i add to my activity class thread, the app stack after implement data to variable,
but when i use handler(with postDelay) it works fine.
1.why?

the code (mapView and userPointOverlay are class private local variables):

using thread:

                new Thread(new Runnable()       //2.5sec delay between switches
                {

                    @Override
                    public void run()
                    {
                        try
                        {
                            Thread.sleep(5000);             
                            mapView.getOverlays().remove(userPointOverlay); 
                        } catch (InterruptedException e)
                        {
                            e.printStackTrace();
                        }                           
                    }
                }).start();

using handler:

                handler.postDelayed(new Runnable()
                {

                    @Override
                    public void run()
                    {
                        mapView.getOverlays().remove(userPointOverlay);                     
                    }
                }, 5000);   

2.what is the main diffrence between thread and handler? i understood that the handler
run on the thread i call him from it (share with main thread cpu time), its currect?

  1. it look like i have access to class local variables from handler. but in thread, the eclipse let me write local class variables in thread but when it starts the address of this locals is not as the thread locals and i dont hava access to this class locals when thread run.

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-12T01:07:39+00:00Added an answer on June 12, 2026 at 1:07 am

    For the 1st option, it is forbidden to access views such as mapView or any UI component from another thread other than the UI thread, which is why the Thread version will fail.

    For a delay, the 2nd option using the Handler is the better way to do it and does not fail because the Handler is declared on the UI thread, which brings an important point about Handlers – Handlers operate on the thread that they are created on, but that thread must be initialized as Looper thread, such as the UI thread.

    It would also be great if you can post the exception for clarity.

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

Sidebar

Related Questions

I have written an app for the android. I want to make this ad
I am planning to add a feature to an existing Android App. Because I
I have been programming an Android App for a while and we want to
I want to write an Android application that can display some data received(polled) from
I am programming something like e-mail for my users. I want to allow people
I am pretty new to thread-safe programming, and was wondering if I have something
Almost every ios app now has something like Feed option. Programming that usually includes
I'm new to Web programming! I try to make an app (something like Client
I'm very new to Android programming, so this is probably something pretty basic. I
I am going to create game for android, this game has multiplayer mode, so

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.