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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T10:30:04+00:00 2026-06-07T10:30:04+00:00

I have an Activity that has an IntentFilter and a BroadcastReceiver, and I register

  • 0

I have an Activity that has an IntentFilter and a BroadcastReceiver, and I register them in my onCreate().

IntentFilter filter = new IntentFilter(ACTION_RCV_MESSAGE);
filter.addCategory(Intent.CATEGORY_DEFAULT);
receiver = new MessageReceiver();
registerReceiver(receiver, filter);

But upon ending my app, Logcat says:

07-03 01:38:19.567: ERROR/ActivityThread(304): android.app.IntentReceiverLeaked: Activity com.intentservicetest5.IntentServiceTest5Activity has leaked IntentReceiver com.intentservicetest5.IntentServiceTest5Activity$MessageReceiver@44efe8a8 that was originally registered here. Are you missing a call to unregisterReceiver()?

But I do have

public void onDestroy(Bundle savedInstanceState){
    unregisterReceiver(receiver);
}

Why is my Activity still leaking when I do call unregisterReceiver()?

  • 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-07T10:30:07+00:00Added an answer on June 7, 2026 at 10:30 am

    Per the Activity Lifecycle, your app is killable any time after onPause() on most devices (any device with less than Android 3.0 / API level 12), and any time after onStop() on any device. That means onDestroy() is not guaranteed to be called. The best place in an Activity to register and unregister for broadcasts, then, is onResume() and onPause(), respectively:

    @Override
    protected void onResume() {
        super.onResume();
    
        IntentFilter filter = new IntentFilter(ACTION_RCV_MESSAGE);
        filter.addCategory(Intent.CATEGORY_DEFAULT);
        receiver = new MessageReceiver();
        registerReceiver(receiver, filter);
    }
    
    @Override
    protected void onPause() {
        super.onPause();
    
        unregisterReceiver(receiver);
    }
    

    Note that as @VipalShah pointed out, you were using the wrong signature for onDestroy(). This is why unregisterReceiver() wasn’t being called. Using @Override will help you catch this kind of problem.

    Also note that the symmetry between onPause() and onResume() is intentional. If you look at the Activity lifecycle article linked to above, you’ll see that onResume() is called during the initial start-up, not just when resuming from pause. So you only need to register for the broadcast here, not in onCreate().

    Finally, note that I used your code for simplicity. In reality, you’ll probably want to set up your IntentFilter and MessageReceiver in onCreate(), and then just call registerReceiver() in onResume().

    Update: One more important note. As per Implementing the lifecycle callbacks:

    Your implementation of these lifecycle methods must always call the superclass implementation before doing any work.

    Many people here were showing the call to super.onWhatever() at the end of the method rather than at the beginning.

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

Sidebar

Related Questions

My app needs to have a intent-filter that responds to a Intent that has
I've an Activity in one of my apps that has an Intent filter, but
I have an Activity class which has an attribute that references an AsyncTask instance
Assume that we have 3 different activities. Each activity has its own XML file
So I have my main activity that has some views and I have an
I have an app that has a list as its main activity and then
I have an Android widget that has a configure activity. I also have an
I have an application that contains two Activities with <intent-filter> <action android:name=android.intent.action.MAIN/> <category android:name=android.intent.category.LAUNCHER/>
I have an activity that has two layouts one in the folder layout and
I have an activity that has a TabHost containing a set of TabSpecs each

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.