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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T04:40:32+00:00 2026-05-21T04:40:32+00:00

I am referring to http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/app/AlarmService_Service.html There the runnable of the thread looks like this

  • 0

I am referring to http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/app/AlarmService_Service.html

There the runnable of the thread looks like this

Runnable mTask = new Runnable() 
{        
    public void run() 
    {  
        Log.v("service", "thread is running after 5 min");
        // Normally we would do some work here...  for our sample, we will           
        // just sleep for 30 seconds.            
        long endTime = System.currentTimeMillis() + 15*1000;            
        while (System.currentTimeMillis() < endTime) 
        {                
            synchronized (mBinder) 
            {                    
                try 
                {                        
                    mBinder.wait(endTime - System.currentTimeMillis());      
                } 
                catch (Exception e) 
                {                    

                }                
            }            
        }            // Done with our work...  stop the service!            
        AlarmService_Service.this.stopSelf();     
    }    
}

I admit that I have some problems with the concept of synchronized… The thread runs the while loop to wait 15s, within that loop I have wait for 15s. So how would the runnable look like if I just want to write a log entry e.g. Log.v(TAG,TEXT);? What would change if I want to write a new entry into my own database table?

Thanks, A.

  • 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-21T04:40:33+00:00Added an answer on May 21, 2026 at 4:40 am

    If you just want a log statement then the following will work fine

    Runnable mTask = new Runnable() 
    {        
        public void run() 
        {  
            Log.v("TAG", "Some verbose log message");
        }    
    }
    

    Whether you need to use synchronized on an object depends on whether object is thread-safe or not. If it is not thread-safe, then you will need to ensure that only one thread access the object at a time by using a synchronized block. In your example mBinder is not thread-safe, so in order to call the wait method of the binder you need to ensure that you are the only thread accessing it.

    A runnable is most often used to execute code in a different thread, so that long running operations (such as IO, but in this case just waiting) do not block the UI thread.

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

Sidebar

Related Questions

I am refering to http://developer.android.com/reference/android/app/Activity.html . I have an activity which can be interrupted
i am trying to display google map on Android refering to this tutorial http://developer.android.com/resources/tutorials/views/hello-mapview.html
You can take a look at the app I'm referring to at: http://github.com/585connor/QA So,
Here is example code I am referring to: http://xml.apache.org/xalan-j/usagepatterns.html#sax First, notice that everything that
From WolframAlpha: http://mathworld.wolfram.com/Function.html While this notation is deprecated by professional mathematicians, it is the
A sample bit of code: <script type=text/javascript src=http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js></script> <div id=myinfo>info</div> <input id=clickme type=button value=click
I'm trying to create a page which looks somewhat like this: http://www.drmichaelbogdan.com/plastic-surgery/ (I'm referring
In Apple's documentation for their example of a Singleton, and I do understand there's
I am referring to exception messages that show the developer is incorrectly using an
From this article http://www.stuartellis.eu/articles/erb referring to thread safety levels: At this level, the specified

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.