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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:35:41+00:00 2026-06-13T05:35:41+00:00

I’m trying to create a searchable activity that gets its results from the google

  • 0

I’m trying to create a searchable activity that gets its results from the google places API, I’ve created a content provider and put some code to do the HTTP request to google and parse the result.

The problem is that the web request needs to be done asynchronously to stop it blocking the UI thread, when it is done like this the content provider returns the MatrixCursor before the web request has completed making the results appear the next time the text box changes instead of when the text actually changes.

Is there any way around this?

Here is my code for my search content provider:


import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject;

import android.app.SearchManager; import android.content.ContentProvider; import android.content.ContentValues; import android.database.Cursor; import android.database.MatrixCursor; import android.net.Uri; import android.util.Log;

import com.loopj.android.http.*;

public class LocationsSuggestionProvider extends ContentProvider { private static final String[] COLUMNS = { "_id", // must include this column SearchManager.SUGGEST_COLUMN_TEXT_1}; public MatrixCursor cursor = new MatrixCursor(COLUMNS); public LocationsSuggestionProvider() {

}
@Override
public int delete(Uri arg0, String arg1, String[] arg2) {
    return 0;
}

@Override
public String getType(Uri uri) {

    return null;
}

@Override
public Uri insert(Uri uri, ContentValues values) {
    return null;
}

@Override
public boolean onCreate() {
    return false;
}

@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
    if(selectionArgs[0].length() >= 2 && selectionArgs[0].length() < 75)
    {
        AsyncHttpClient client = new AsyncHttpClient();
        try {
            Log.d("Bustimes","https://maps.googleapis.com/maps/api/place/autocomplete/json?input="+ URLEncoder.encode(selectionArgs[0].trim(), "UTF-8") +"&sensor=false&key=AIzaSyCvGtqoDK_SoBWG94CKOjymnOc-dzXr8WA&language=en-GB&components=country:gb");
            client.get("https://maps.googleapis.com/maps/api/place/autocomplete/json?input="+ URLEncoder.encode(selectionArgs[0].trim(), "UTF-8") +"&sensor=false&key=AIzaSyCvGtqoDK_SoBWG94CKOjymnOc-dzXr8WA&language=en-GB&components=country:gb", new AsyncHttpResponseHandler() {
                @Override
                public void onSuccess(String response) {
                    JSONObject jObject = null;
                    try {
                        jObject = new JSONObject(response);

                        JSONArray predictions = jObject.getJSONArray("predictions");
                        for(int i = 0;i < predictions.length(); i++)
                        {
                            JSONObject prediction = predictions.getJSONObject(i);
                            LocationsSuggestionProvider.this.cursor.addRow(new Object[] {i,prediction.getString("description").toString()});
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
            });
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }
    MatrixCursor returnMatrix = cursor;
    cursor = new MatrixCursor(COLUMNS);
    return returnMatrix;
}
@Override
public int update(Uri uri, ContentValues values, String selection,
        String[] selectionArgs) {
    return 0;
}

}

  • 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-13T05:35:42+00:00Added an answer on June 13, 2026 at 5:35 am

    It turns out that you don’t need to do any of this asynchronously because the request to the content provider isn’t ran on the UI thread anyway. This means you can just do the web request normally without an async task or whatever you would do and it will work fine.

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

Sidebar

Related Questions

I'm trying to create an if statement in PHP that prevents a single post
Basically, what I'm trying to create is a page of div tags, each has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to select an H1 element which is the second-child in its group
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm making a simple page using Google Maps API 3. My first. One marker
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text

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.