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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:41:59+00:00 2026-05-27T11:41:59+00:00

I am having an application where user can register and unregister receiver from Settings

  • 0

I am having an application where user can register and unregister receiver from Settings to enable and disable service of app.

I have taken a toggle button to let user control the app service.I registered a receiver on its on state and unregistered the same on its off state.

It works fine when I enable the app service by making toggle button in on state,it successfully registered the receiver and gives me toast.

But when I try to click again on toggle button making it in off state,it gives me exception on line unregisterReceiver(..).

Here is the code:

    ...
    onoff.setOnClickListener(new OnClickListener() 
    {               
        @Override
        public void onClick(View v)
        {   
            BroadcastReceiver b=new SmsReactor();
            if(onoff.isChecked())
            {
                try               
                {                               
                    IntentFilter iFilter=new IntentFilter("android.provider.Telephony.SMS_RECEIVED");
                    iFilter.setPriority(100);
                    registerReceiver(b,iFilter);

                    Toast.makeText(context,"Service Started!",Toast.LENGTH_SHORT).show();
                }
                catch (Exception e) {

                    onoff.setChecked(false);
                    Toast.makeText(context,"Sorry,Couldn't start the service!Try again.",Toast.LENGTH_SHORT).show();
                    e.printStackTrace();                  
                }                   
          }
          else
          {
                try
                {                           
                    unregisterReceiver(b); // here it gives me exception                
                    Toast.makeText(context,"Service Stopped!",Toast.LENGTH_SHORT).show();
                }
                catch (Exception e){

                    onoff.setChecked(true);
                    Toast.makeText(context,"Sorry,Couldn't stop the service!Try again.",Toast.LENGTH_SHORT).show();
                    e.printStackTrace();
                }           
          }
       }
   });
    ...

And the logcat:

12-07 10:16:37.113: W/System.err(445): java.lang.IllegalArgumentException: Receiver not registered: com.xxx.android.xxx.SmsReactor@44e1c500
12-07 10:16:37.113: W/System.err(445):  at android.app.ActivityThread$PackageInfo.forgetReceiverDispatcher(ActivityThread.java:667)
12-07 10:16:37.123: W/System.err(445):  at android.app.ApplicationContext.unregisterReceiver(ApplicationContext.java:747)
12-07 10:16:37.123: W/System.err(445):  at android.content.ContextWrapper.unregisterReceiver(ContextWrapper.java:321)
12-07 10:16:37.123: W/System.err(445):  at com.xxx.android.xxx.Settings$2.onClick(Settings.java:90)
12-07 10:16:37.123: W/System.err(445):  at android.view.View.performClick(View.java:2364)
12-07 10:16:37.123: W/System.err(445):  at android.widget.CompoundButton.performClick(CompoundButton.java:98)
12-07 10:16:37.123: W/System.err(445):  at android.view.View.onTouchEvent(View.java:4179)
12-07 10:16:37.123: W/System.err(445):  at android.widget.TextView.onTouchEvent(TextView.java:6541)
12-07 10:16:37.123: W/System.err(445):  at android.view.View.dispatchTouchEvent(View.java:3709)
12-07 10:16:37.123: W/System.err(445):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
12-07 10:16:37.123: W/System.err(445):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
12-07 10:16:37.123: W/System.err(445):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
12-07 10:16:37.123: W/System.err(445):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
12-07 10:16:37.123: W/System.err(445):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
12-07 10:16:37.123: W/System.err(445):  at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659)
12-07 10:16:37.123: W/System.err(445):  at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)
12-07 10:16:37.123: W/System.err(445):  at android.app.Activity.dispatchTouchEvent(Activity.java:2061)
12-07 10:16:37.123: W/System.err(445):  at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643)
12-07 10:16:37.123: W/System.err(445):  at android.view.ViewRoot.handleMessage(ViewRoot.java:1691)
12-07 10:16:37.123: W/System.err(445):  at android.os.Handler.dispatchMessage(Handler.java:99)
12-07 10:16:37.133: W/System.err(445):  at android.os.Looper.loop(Looper.java:123)
12-07 10:16:37.133: W/System.err(445):  at android.app.ActivityThread.main(ActivityThread.java:4363)
12-07 10:16:37.133: W/System.err(445):  at java.lang.reflect.Method.invokeNative(Native Method)
12-07 10:16:37.133: W/System.err(445):  at java.lang.reflect.Method.invoke(Method.java:521)
12-07 10:16:37.133: W/System.err(445):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
12-07 10:16:37.133: W/System.err(445):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
12-07 10:16:37.133: W/System.err(445):  at dalvik.system.NativeStart.main(Native Method)

Please help me finding out where I am doing wrong?! Any help appreciated.

Thanks in advance!

  • 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-27T11:41:59+00:00Added an answer on May 27, 2026 at 11:41 am

    Just define this BroadcastReceiver b=new SmsReactor();
    outside of Button’s click like, OnCreate() and try again let me know what happen,

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

Sidebar

Related Questions

Can a user install my application from iTunesStore if he is having iPhone OS
The set-up: I have an android application that so far can register a user
I am having a number of controls in my application(which user can add to
In my application screen, i am having a field, where user can to choose
I have an application where the admin user can create users and upload documents
I have a drawing app where the user can draw lines with their finger,
I've a scenario in which user can make a selection from a grid (having
So I'm having this application that verifies weather a user can log-in or not.
I have an application where each user can choose a custom layout. The layouts
I have an MVC3 application, in which the user is sent an email, having

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.