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

  • Home
  • SEARCH
  • 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 7738367
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T08:14:45+00:00 2026-06-01T08:14:45+00:00

I am writing a small program that gets activated when sms is received.We need

  • 0

I am writing a small program that gets activated when sms is received.We need to start/stop service through graphical user interface. I am using a check box and a button to start or stop the service.

The code is as followed.

 private smsBroadcast b;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

 }

public void onclick(View i)
{
    CheckBox c=(CheckBox)findViewById(R.id.checkBox1);
      b=new smsBroadcast();
    try{
    if(c.isChecked())
    registerReceiver(b, new IntentFilter("android.provider.Telephony.SMS_RECEIVED"));
    else
    unregisterReceiver(b);
    }
    catch(Exception e)
    {

    }
    finish();
}

Here smsBroadcast is the broadcastReceiver class.
When we click the button, it is showing some exceptions in logcat.
The exceptions are as followed…

           03-31 12:01:33.923: E/ActivityThread(806): Activity examples.sms.SmssmsActivity has leaked IntentReceiver examples.sms.smsBroadcast@405457f0 that was originally registered here. Are you missing a call to unregisterReceiver()?
           03-31 12:01:33.923: E/ActivityThread(806): android.app.IntentReceiverLeaked: Activity examples.sms.SmssmsActivity has leaked IntentReceiver examples.sms.smsBroadcast@405457f0 that was originally registered here. Are you missing a call to unregisterReceiver()?
           03-31 12:01:33.923: E/ActivityThread(806):   at android.app.LoadedApk$ReceiverDispatcher.<init>(LoadedApk.java:756)
           03-31 12:01:33.923: E/ActivityThread(806):   at android.app.LoadedApk.getReceiverDispatcher(LoadedApk.java:551)
           03-31 12:01:33.923: E/ActivityThread(806):   at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:795)
           03-31 12:01:33.923: E/ActivityThread(806):   at android.app.ContextImpl.registerReceiver(ContextImpl.java:782)
           03-31 12:01:33.923: E/ActivityThread(806):   at android.app.ContextImpl.registerReceiver(ContextImpl.java:776)
           03-31 12:01:33.923: E/ActivityThread(806):   at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:318)
           03-31 12:01:33.923: E/ActivityThread(806):   at examples.sms.SmssmsActivity.onclick(SmssmsActivity.java:25)
           03-31 12:01:33.923: E/ActivityThread(806):   at java.lang.reflect.Method.invokeNative(Native Method)
           03-31 12:01:33.923: E/ActivityThread(806):   at java.lang.reflect.Method.invoke(Method.java:507)
           03-31 12:01:33.923: E/ActivityThread(806):   at android.view.View$1.onClick(View.java:2139)
           03-31 12:01:33.923: E/ActivityThread(806):   at android.view.View.performClick(View.java:2485)
           03-31 12:01:33.923: E/ActivityThread(806):   at android.view.View$PerformClick.run(View.java:9080)
           03-31 12:01:33.923: E/ActivityThread(806):   at android.os.Handler.handleCallback(Handler.java:587)
           03-31 12:01:33.923: E/ActivityThread(806):   at android.os.Handler.dispatchMessage(Handler.java:92)
           03-31 12:01:33.923: E/ActivityThread(806):   at android.os.Looper.loop(Looper.java:123)
           03-31 12:01:33.923: E/ActivityThread(806):   at android.app.ActivityThread.main(ActivityThread.java:3683)
           03-31 12:01:33.923: E/ActivityThread(806):   at java.lang.reflect.Method.invokeNative(Native Method)
           03-31 12:01:33.923: E/ActivityThread(806):   at java.lang.reflect.Method.invoke(Method.java:507)
           03-31 12:01:33.923: E/ActivityThread(806):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
           03-31 12:01:33.923: E/ActivityThread(806):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
           03-31 12:01:33.923: E/ActivityThread(806):   at dalvik.system.NativeStart.main(Native Method)
  • 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-01T08:14:46+00:00Added an answer on June 1, 2026 at 8:14 am

    you need to register the receiver in onResume and unregister in onPause

    http://developer.android.com/reference/android/content/BroadcastReceiver.html

    If registering a receiver in your Activity.onResume() implementation, you should unregister it in Activity.onPause(). (You won’t receive intents when paused, and this will cut down on unnecessary system overhead). Do not unregister in Activity.onSaveInstanceState(), because this won’t be called if the user moves back in the history stack.

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

Sidebar

Related Questions

I'm writing a small command-line program that asks the user for polynomials in the
I'm pretty new to C# and Visual Studio. I'm writing a small program that
I am writing a small test program that gives the following xml file as
in small program I'm writing, I have to parse a line of user input.
I am using libcurl for a small program that gets data from an input
I'm writing a small program that creates a new Windows desktop, switches to it
I'm writing a small C program that uses librt. I'm quite surprised that the
I'm writing a small program in C that will read input from the console.
I'm just a beginner in C++. I'm writing small and simple program that prints
I am writing a small program in C++ that receives mic input and does

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.