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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T05:19:43+00:00 2026-06-04T05:19:43+00:00

I have a broadcastreciever which start a long operation (uploading process). In the code

  • 0

I have a broadcastreciever which start a long operation (uploading process).
In the code of a service started from the Activity class, I need to register this receiver in a new thread.

I have checked this post Are Android's BroadcastReceivers started in a new thread? but I need a more concrete example about using Context.registerReceiver(BroadcastReceiver receiver, IntentFilter filter, String broadcastPermission, Handler scheduler)

Actually I need to know how to create a new thread from a service and to register the receiver and attached to this thread.

Thank you very much.
RA

  • 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-04T05:19:47+00:00Added an answer on June 4, 2026 at 5:19 am

    In your service’s onCreate():

    private Handler handler; // Handler for the separate Thread
    
    HandlerThread handlerThread = new HandlerThread("MyNewThread");
    handlerThread.start();
    // Now get the Looper from the HandlerThread so that we can create a Handler that is attached to
    //  the HandlerThread
    // NOTE: This call will block until the HandlerThread gets control and initializes its Looper
    Looper looper = handlerThread.getLooper();
    // Create a handler for the service
    handler = new Handler(looper);
    // Register the broadcast receiver to run on the separate Thread
    registerReceiver (myReceiver, intentFilter, broadcastPermission, handler);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an activity which displays some data fetched from the server. If no
I have on Service that must communicate with an Activity (MyActivity) through a BradcastReceiver.
I'm using a timer which needs context. Now I have the following code :
i have this broadcastreceiver that executes some code from time to time and triggers
So, I'll explain my situation. I have a Service which is catching the events
Is it possible that BroadcastReceiver in an activity which have gone to background receiving
I have an application which requires data to be fetched from a received message
I have a case in which I have to start some non-UI action N
I have a service which runs two asynctasks. One is for receiving multicast packets
I have created a service running in background which saves gps points on the

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.