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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:17:50+00:00 2026-06-11T11:17:50+00:00

I want a Broadcastreceiver to be called every time Intent.ACTION_BATTERY_CHANGED gets broacasted so I

  • 0

I want a Broadcastreceiver to be called every time Intent.ACTION_BATTERY_CHANGED gets broacasted so I can track some data.

What I have now:

public class ReceiverApplication extends Application {

    @Override
    public void onCreate() {
        // Register Receiver
    }
    public static BroadcastReceiver myReceiver = new BroadcastReceiver()  {

        @Override
        public void onReceive(Context context, Intent intent) {
            // Start Service to progress data
        }       
    };  
}

This works fine UNTIL I use the Recent Apps “Taskmanager” to swipe away one of my preference Screens or my main activity. Then the BroadcastReceiver doesnt get called anymore. If I start one of my activities, onCreate() of ReceiverApplication gets called and it starts working again.

I could work around that by having a empty service running all the time. The service doesn’t seem to get killed by swiping an activity away and onCreate() gets called after some time and restarts the BroadcastReceiver without doing anything. The problem here is that I don’t want a service to run all the time.

So, how can I get a Broadcastreceiver outside of any Acitivity or Service which can receive Broadcasts as long as the user wants?

  • 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-11T11:17:51+00:00Added an answer on June 11, 2026 at 11:17 am

    Instead of nesting a broadcast receiver and registering it dynamically, declare one in your Android manifest According to the documentation, BATTERY_CHANGED cannot be declared in the manifest:

    You can not receive this through components declared in manifests, only by explicitly registering for it with Context.registerReceiver(). See ACTION_BATTERY_LOW, ACTION_BATTERY_OKAY, ACTION_POWER_CONNECTED, and ACTION_POWER_DISCONNECTED for distinct battery-related broadcasts that are sent and can be received through manifest receivers.

    I would register a broadcast receiver to recieve all these events:

        <receiver
            android:name="MyBroadcastReceiver">
            <intent-filter>
                <action
                    android:name="android.intent.action.BATTERY_LOW" />
                <category
                    android:name="android.intent.category.DEFAULT" />
            </intent-filter>
            <intent-filter>
                <action
                    android:name="android.intent.action.BATTERY_OKAY" />
                <category
                    android:name="android.intent.category.DEFAULT" />
            </intent-filter>
            <intent-filter>
                <action
                    android:name="android.intent.action.ACTION_POWER_CONNECTED" />
                <category
                    android:name="android.intent.category.DEFAULT" />
            </intent-filter>
            <intent-filter>
                <action
                    android:name="android.intent.action.ACTION_POWER_DISCONNECTED" />
                <category
                    android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </receiver>
    

    The broadcast receiver will be notified regardless of whether your app is running or not.

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

Sidebar

Related Questions

i have this broadcastreceiver that executes some code from time to time and triggers
want to have a Hyperlink-Button in a gridView in which I can display a
I have class that extends BroadcastReceiver and gets all new sms. When I get
My app scenario is that I want to track employees location. I have a
I wrote sms application for which I wrote BroadcastReceiver. I want to get data
I want to implement my BroadcastReceiver on pressing some key combination (say if i
I have a table called student which I want to populate from the server.
I have a BroadcastReceiver that I'm using to send data to another activity which
I want to activate a service from my broadcastReceiver, this is my code but
I have a broadcast receiver which receive an internet state changes. I want to

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.