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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:50:43+00:00 2026-05-15T10:50:43+00:00

in my android app i have an ui-update-thread that keeps all my views up-to-date.

  • 0

in my android app i have an ui-update-thread that keeps all my views up-to-date.

protected Thread UIUpdateThread = new Thread()
{
 @Override
 public void run()
 {
  while(true)
  {
    query_some_data_from_service(); // gets some "fresh" data from a service
    UIUpdateHandler.sendEmptyMessage(0); // will update all ui elements with the new values
    sleep(1234);
  }
 }
};

i start this thread in onCreate() with

UIUpdateThread.start();

and everything works just fine 🙂 when i leave the activity (e.g. because i switch to another activity) i call

UIUpdateThread.interrupt();

within onStop() to prevent the thread from running all the time. if i dont do this, it would keep running even if i close the app !?!?!!

problem is: how do i bring this thread back to life when returning from some other activity to this one? run() doesnt work, calling the initial start() in some other method like onResume() crashes the app.

i already tried a lot of things, but nothing seems to work 🙁

  • 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-15T10:50:44+00:00Added an answer on May 15, 2026 at 10:50 am

    Atmocreation’s answer is the correct one…assuming that your implementation is a good idea in the first place.

    First, the thread that you show here runs briefly and immediately terminates on its own, so you would not need to call interrupt() to stop it. In that case, you are probably better served switching to an AsyncTask rather than your own thread and handler, as you will need less code and can take advantage of AsyncTask‘s thread pool.

    If your real thread is not what you show here, but some sort of infinite loop, that is a bad idea in general. Never create busy loops, particularly in Android. Most likely, there is a better solution for your problem, perhaps one that would avoid the need for interrupt() as well.

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

Sidebar

Related Questions

I started developing an android app that have to interact with MMS attachements, in
I am starting to develop an Android app and I have seen that in
I have a android app that is quite simple it fetches data from the
I have android app that talks to server and syncs some data int SQLite
I have an android app that listens for json commands over a socket. I
We have an Android app that periodically polls for data and updates the display.
My Android app has an Update class and I have, in the same app,
In my android app I have fragments, and one of them is very heavy
I am working on an android app and have to use remote database for
I am currently writing my first Android app and have based most of my

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.