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

The Archive Base Latest Questions

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

I have a case in which I have to start some non-UI action N

  • 0

I have a case in which I have to start some non-UI action N seconds after power has been connected to the device. That action could be also started by user via UI.

I have a BroadcastReceiver defined in AndroidManifest.xml which listens for ACTION_POWER_CONNECTED.

I have a service that does required action on onStartCommand. My question is – what is the right way to start that service in case of when action is triggered by broadcast?

I have two options in mind:

  1. One-shot timer task. However I think it might be wrong because of according to docs, I could’t start any async tasks from BroadcastReceiver.

  2. Redesign service:

    • start action at onStartCommand, if action was triggered by user
    • start timer task and do action at timer shot – same logic as in 1. but inside service – if action was triggered by broadcast.

I am inclined to 2. It will make code a bit more complex, but it seems it is only right way.

-Lev

  • 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-23T15:35:24+00:00Added an answer on May 23, 2026 at 3:35 pm

    The correct way is #2. That’s because as soon as you leave onReceive application process might be killed. And your TimerTask won’t help in such case.

    As an alternative solution, use AlarmManager and its set function to schedule pending service intent. This is probably the best solution in your case.

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

Sidebar

Related Questions

Please give me some tips for this case. I have an iPhone APP which
I have a CLI application, which is digging some data, in case of need,
I'm preparing for an exam and after going over some sample exercises (which have
I have a Windows.Forms component which has a mySize property that returns a Size
I am creating a traceability matrix for PRD. I have test case _id which
I have a pretty simple case which I started solving using foreach(), but then
Ok here I have a switch case statement which is falling through and trying
I have an app where users can sign up with Facebook, in which case
I have to compare two strings for case insensitive equality which one is faster
I have a Lucene index which is currently case sensitive. I want to add

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.