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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T03:51:41+00:00 2026-06-06T03:51:41+00:00

When this callback is made in my app, I have quite a bit work

  • 0

When this callback is made in my app, I have quite a bit work to do (reading & writing to SQL db through an ORM lib and a number of distance based calculations). Naturally I am concerned about not blocking the main UI thread so I’ve been trying (unsuccessfully) to find out if this is the thread on which the callback is made. If it is, I’m intending to do all the afore-mentioned work on an AsyncTask triggered when the callback is made. This same AsyncTask will receive events from 2 separate activity classes as well. (Responding to user input etc..)

A lot of the discussion I have found around this callback seems to be based around people trying to change the thread on which the callback is actually received. This makes no sense to me. Surely the platform determines the context of this callback and the sensible thing to do when it’s received is offload any serious work onto another thread, for which AsyncTask seems appropriate.

If anyone can outline a successful pattern they’ve used here it would be really useful.

  • 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-06T03:51:43+00:00Added an answer on June 6, 2026 at 3:51 am

    According to the Android reference documentation for LocationManager:

    The calling thread must be a Looper thread such as the main thread of
    the calling Activity.

    This means that the Thread that initializes the callback must be the main Thread or a Looper Thread.

    I’ve found the best way to handle this is to register an OnLocationChanged receiver on the main Thread. Then, in my callback I’ll create a Runnable to send to a background Thread where I’ll perform any long-running tasks (like writing to the database).

    ExecutorService mThreadPool = Executors.newSingleThreadExecutor();
    
    @Override
    public void onLocationChanged(Location location) {
        mThreadPool.execute(new Runnable() {
            @Override
            public void run() {
                // Perform your long-running tasks here.
                //...
            }
        });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this static callback function in MyClass, and I try to call another
I have a Rails app running on port 3101 and I made it available
I have been working on this app for at least 3-4 months and just
I am trying to do the following: function main(callback) { $.ajax('server-side', function() { this.callback.call(hello);
In the code below: DbModels.prototype.updateById = function(_collection, id, field, value, callback) { this.getCollection(_collection, function(error,
I created this test program to find out what happens when a timer callback
Is the Callback supposed to be called on a different thread? Using this code:
This my jquery function, function getRecordspage(curPage, pagSize) { // code here $(.pager).pagination(strarr[1], { callback:
I've created this basic 3D Demo using OpenGL/SDL. I handled the keyboard callback so
I want to use this function EnumWindows(EnumWindowsProc, NULL);. The EnumWindowsProc is a Callback function:

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.