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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:35:08+00:00 2026-05-23T03:35:08+00:00

I am working on an application which needs to do a WiFi scan every

  • 0

I am working on an application which needs to do a WiFi scan every 5-6 seconds. WiFiScanner class is implemented as a service and called from the main Activity. In order to repeat tasks every few seconds, I have used Handler with postDelayed with an interval of 5000 msecs. After installing on the device the application runs fine first time. Stopping the WiFi scan process, closing and immediately reopening the application causes it to crash. I suppose its because I haven’t stopped the Handler explicitly in the main activity by calling removecallbacks on the runnable, instead clicking stop would simply stop the service. Here’s what logcat throws on the error.

06-14 12:30:58.181: ERROR/AndroidRuntime(23534): java.lang.RuntimeException: Error receiving broadcast Intent { act=android.net.wifi.SCAN_RESULTS } in com.test.example.WiFiScanner$1@2b0a3880

I was looking through stackoverflow and found suggestions to use an AlarmManager instead. But wouldn’t this require me to implement a BroadcastReciever class for the purpose as it says here? Is there any other alternative to Handler to doing repetitive tasks in a service invoked from the Main Activity?

  • 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-23T03:35:09+00:00Added an answer on May 23, 2026 at 3:35 am

    well you can just bind the service instead of starting it. that means it’s a local service which will get stopped when there arent any more activities bound to it. but be carefull because the service runs in the ui thread so move things in a background thread. what i have commonly used in situations like this is a handler that postDelayed a runnable executing an async task where you can do whatever you want to do and then rescheduling it so it runs in some time period. also remove the callbacks when the service is destroyed and start it sticky so that if it is killed it restarts and you can also remove the callbacks on start.

    As an alternative you can use an intent service or a simple service with alarms that is started by the alarm on specific time periods, that calls selfStop after it has completed a scan. but if you are running frequent checks then this creates an overhead because the service needs to be created over and over again (so better keep it running then).

    there is also the timerTask class but i simply find this 2 solutions better. the timer class introduces a new thread

    see: Timer

    And This for an implementation

    and here is someone that tried to do the same thing as you are:

    Timer task and answers

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

Sidebar

Related Questions

I am working on application which needs to fetch values from database and pass
I am currently working on an application which needs to send MultiMap from .Net
I'm working on iphone application which needs to run offline at an exhibition. It
I'm a newbie C++ developer and I'm working on an application which needs to
I am working on an application which starts as a service but only if
I'm working on an application which has data imported from a foreign (and wholly
I am working on an application which needs to load fonts dynamically based upon
I'm working on a background service which needs to ask several users' iTunes settings
I am working on an application which needs to divert phone calls to other
I am working on an application which needs to rotate the slider at one

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.