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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:26:06+00:00 2026-05-26T13:26:06+00:00

I am developing an application that is using bluetooth to automatically connect to nearby

  • 0

I am developing an application that is using bluetooth to automatically connect to nearby paired devices. For that reason I need to listen to bluetooth specific broadcasts like ACTION_FOUND, DISCOVERY_FINISHED etc. , I have to register a broadcast receiver which listens for those broadcasts and performs actions accordingly. Thing is that I need this broadcast receiver to work at any time in the background of my app. I tried to fit it into an intentservice but it turned out that it finishes to fast and onDestroy is called ending my receiver. To overcome this problem I inserted an infinite loop which breaks only when an attribute is turned from true to false. Somehow I feel this is a bad practice and so I am asking you if there is any better solution?

PS. Should I fit the receiver in the main activity? And when does it gets destroyed? Is onDestroy called only when I exit my application with back button, or kill the process with a task killer, or does it occur also when I enter another GUI window in my app?

Thanks, Mike

  • 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-26T13:26:06+00:00Added an answer on May 26, 2026 at 1:26 pm

    If you register your receiver dynamically (Context.registerReceiver) it is your job to unregister it (Context.unregisterReceiver) before your activity is paused. And as reading from the documentation:

    You won’t receive intents when paused, and this will cut down on unnecessary system overhead

    onPause will be called when something hides your activity. And you can re register in onResume.

    However, this is not what you need. If you want to receive broadcasts even while your application is dead, you need to declare it in the Android Manifest. I think this code will work:

        <receiver android:name=".YourReceiverClassName">
            <intent-filter>
                <action android:name="android.bluetooth.adapter.action.ACTION_FOUND"/>
                <action android:name="android.bluetooth.adapter.action.ACTION_DISCOVERY_FINISHED"/>
            </intent-filter>
        </receiver>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm developing an application that among other things, enumerates all input audio devices (using
I'm developing an application that need to load Bitmap. And using a SoftReference for
I'm currently developing a PHP application that's using an Access database as a backend.
I am developing an application that can be extended using plug-ins. The plug-ins will
I am developing a WPF application that must run using Windows Classic theme. The
I am developing the chatting application but by using that application two persons are
I'm currently developing an Android application that fetches images using http requests. It would
I'm using Google appengine for developing an web application that is meant to be
I am developing a .NET application (using C#) that needs to massage some Adobe
I am using SQLite in an application that I am developing. I am trying

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.