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

  • Home
  • SEARCH
  • 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 5839197
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T11:33:09+00:00 2026-05-22T11:33:09+00:00

I’m trying to synchronize two blocks of code for an Android app. The first

  • 0

I’m trying to synchronize two blocks of code for an Android app.

The first block uses an AsyncFacebookRunner to make a request for a user’s interests, if any.

If interests were found, a member variable for that user is populated with their interests from the Facebook JSON response.

The second code block checks if the user actually has interests by looking at that member variable. If there are interests, several additional lines of code are executed.

synchronized(this)
{
    if ( (friend.getmActivities().length() == 0) && (friend.getmInterests().length() == 0) )
        friend.requestInterests(mFacebook); // Get that friend's Facebook activities and interests.
}

synchronized(this)
{
    if ( (friend.getmActivities().length() == 0) && (friend.getmInterests().length() == 0) )
    {
        final AlertDialog alertDialog = new AlertDialog.Builder(mContext).create();
        alertDialog.setTitle("Sorry...");
        alertDialog.setMessage("Your friend isn't sharing their interests.");
        alertDialog.setButton("Go Back", new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                alertDialog.dismiss();
            }
        });

        alertDialog.show();
    }
}

I want the second block to wait until friend.requestInterests() is complete before executing.

EDIT: I ended up restructuring my code to utilize the runner’s onComplete method. This all came about when I modified the structure of my program and had to change up everything. Thanks all for the help.

  • 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-22T11:33:10+00:00Added an answer on May 22, 2026 at 11:33 am

    I want the second block to wait until friend.requestInterests() is complete before executing.

    The JVM ensures that the two blocks don’t execute at the same time for the same instance of this.

    If you additionally want to ensure that the second block only gets to run after the first has run, then you can do this using a state variable and wait / notify calls. But a better way is to use one of the synchronization classes such CountDownLatch; e.g.

    private CountDownLatch latch = new CountDownLatch(1);
    
    ...
    
    synchronized(this) {
       // do first actions
    }
    this.latch.countdown();
    
    ....
    
    this.latch.await();
    synchronized(this) {
        // do second
    }
    

    Indeed, if these are the only places where the relevant object state is accessed and updated, you should be able to dispense with the synchronized blocks. The calls to countdown and await will provide the necessary “comes before” relationship to ensure proper synchronization.


    However, @pst’s comment raises the point that there may be a better way to do this using the APIs of the Facebook library framework that your code uses.

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

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
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
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I need to clean up various Word 'smart' characters in user input, including but
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post

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.