Are you missing a call to unregisterReceiver()?


Last Updated:

  1. pramod.deore

    pramod.deore Member This Topic's Starter

    Joined:
    Jan 10, 2010
    Messages:
    22
    Likes Received:
    0
    In my application I am sending a sms programatically, when I ran the application it send sms but on Logcat file it throws following exception

    Code (Text):
    1.  
    2. 02-07 12:38:15.447: ERROR/ActivityThread(839): Activity com.micro.MyTest has leaked IntentReceiver [EMAIL="com.micro.MyTest$1@435a0c70"]com.micro.MyTest$1@435a0c70[/EMAIL] that was originally registered here. Are you missing a call to unregisterReceiver()?
    3. 02-07 12:38:15.447: ERROR/ActivityThread(839): android.app.IntentReceiverLeaked: Activity com.micro.MyTest has leaked IntentReceiver [EMAIL="com.micro.MyTest$1@435a0c70"]com.micro.MyTest$1@435a0c70[/EMAIL] that was originally registered here. Are you missing a call to unregisterReceiver()?
    4. 02-07 12:38:15.447: ERROR/ActivityThread(839):     at android.app.ActivityThread$PackageInfo$ReceiverDispatcher.<init>(ActivityThread.java:707)
    5. 02-07 12:38:15.447: ERROR/ActivityThread(839):     at android.app.ActivityThread$PackageInfo.getReceiverDispatcher(ActivityThread.java:535)
    6. 02-07 12:38:15.447: ERROR/ActivityThread(839):     at android.app.ApplicationContext.registerReceiverInternal(ApplicationContext.java:748)
    7. 02-07 12:38:15.447: ERROR/ActivityThread(839):     at android.app.ApplicationContext.registerReceiver(ApplicationContext.java:735)
    8. 02-07 12:38:15.447: ERROR/ActivityThread(839):     at android.app.ApplicationContext.registerReceiver(ApplicationContext.java:729)
    9. 02-07 12:38:15.447: ERROR/ActivityThread(839):     at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:278)
    10. 02-07 12:38:15.447: ERROR/ActivityThread(839):     at com.micro.MyTest.sendSMS(MyTest.java:98)
    11. 02-07 12:38:15.447: ERROR/ActivityThread(839):     at com.micro.MyTest.onCreate(MyTest.java:42)
    12. 02-07 12:38:15.447: ERROR/ActivityThread(839):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
    13. 02-07 12:38:15.447: ERROR/ActivityThread(839):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2231)
    14. 02-07 12:38:15.447: ERROR/ActivityThread(839):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2284)
    15. 02-07 12:38:15.447: ERROR/ActivityThread(839):     at android.app.ActivityThread.access$1800(ActivityThread.java:112)
    16. 02-07 12:38:15.447: ERROR/ActivityThread(839):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1692)
    17. 02-07 12:38:15.447: ERROR/ActivityThread(839):     at android.os.Handler.dispatchMessage(Handler.java:99)
    18. 02-07 12:38:15.447: ERROR/ActivityThread(839):     at android.os.Looper.loop(Looper.java:123)
    19. 02-07 12:38:15.447: ERROR/ActivityThread(839):     at android.app.ActivityThread.main(ActivityThread.java:3948)
    20. 02-07 12:38:15.447: ERROR/ActivityThread(839):     at java.lang.reflect.Method.invokeNative(Native Method)
    21. 02-07 12:38:15.447: ERROR/ActivityThread(839):     at java.lang.reflect.Method.invoke(Method.java:521)
    22. 02-07 12:38:15.447: ERROR/ActivityThread(839):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:782)
    23. 02-07 12:38:15.447: ERROR/ActivityThread(839):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540)
    24. 02-07 12:38:15.447: ERROR/ActivityThread(839):     at dalvik.system.NativeStart.main(Native Method)
    25. 02-07 12:38:15.496: ERROR/ActivityThread(839): Activity com.micro.MyTest has leaked IntentReceiver [EMAIL="com.micro.MyTest$2@435a13b8"]com.micro.MyTest$2@435a13b8[/EMAIL] that was originally registered here. Are you missing a call to unregisterReceiver()?
    26. 02-07 12:38:15.496: ERROR/ActivityThread(839): android.app.IntentReceiverLeaked: Activity com.micro.MyTest has leaked IntentReceiver [EMAIL="com.micro.MyTest$2@435a13b8"]com.micro.MyTest$2@435a13b8[/EMAIL] that was originally registered here. Are you missing a call to unregisterReceiver()?
    27. 02-07 12:38:15.496: ERROR/ActivityThread(839):     at android.app.ActivityThread$PackageInfo$ReceiverDispatcher.<init>(ActivityThread.java:707)
    28. 02-07 12:38:15.496: ERROR/ActivityThread(839):     at android.app.ActivityThread$PackageInfo.getReceiverDispatcher(ActivityThread.java:535)
    29. 02-07 12:38:15.496: ERROR/ActivityThread(839):     at android.app.ApplicationContext.registerReceiverInternal(ApplicationContext.java:748)
    30. 02-07 12:38:15.496: ERROR/ActivityThread(839):     at android.app.ApplicationContext.registerReceiver(ApplicationContext.java:735)
    31. 02-07 12:38:15.496: ERROR/ActivityThread(839):     at android.app.ApplicationContext.registerReceiver(ApplicationContext.java:729)
    32. 02-07 12:38:15.496: ERROR/ActivityThread(839):     at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:278)
    33. 02-07 12:38:15.496: ERROR/ActivityThread(839):     at com.micro.MyTest.sendSMS(MyTest.java:129)
    34. 02-07 12:38:15.496: ERROR/ActivityThread(839):     at com.micro.MyTest.onCreate(MyTest.java:42)
    35. 02-07 12:38:15.496: ERROR/ActivityThread(839):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
    36. 02-07 12:38:15.496: ERROR/ActivityThread(839):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2231)
    37. 02-07 12:38:15.496: ERROR/ActivityThread(839):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2284)
    38. 02-07 12:38:15.496: ERROR/ActivityThread(839):     at android.app.ActivityThread.access$1800(ActivityThread.java:112)
    39. 02-07 12:38:15.496: ERROR/ActivityThread(839):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1692)
    40. 02-07 12:38:15.496: ERROR/ActivityThread(839):     at android.os.Handler.dispatchMessage(Handler.java:99)
    41. 02-07 12:38:15.496: ERROR/ActivityThread(839):     at android.os.Looper.loop(Looper.java:123)
    42. 02-07 12:38:15.496: ERROR/ActivityThread(839):     at android.app.ActivityThread.main(ActivityThread.java:3948)
    43. 02-07 12:38:15.496: ERROR/ActivityThread(839):     at java.lang.reflect.Method.invokeNative(Native Method)
    44. 02-07 12:38:15.496: ERROR/ActivityThread(839):     at java.lang.reflect.Method.invoke(Method.java:521)
    45. 02-07 12:38:15.496: ERROR/ActivityThread(839):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:782)
    46. 02-07 12:38:15.496: ERROR/ActivityThread(839):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540)
    47. 02-07 12:38:15.496: ERROR/ActivityThread(839):     at dalvik.system.NativeStart.main(Native Method)
    48.  
    49.  
    The method which send sms is as follows

    Code (Text):
    1.  
    2. [SIZE=2][LEFT][/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] sendSMS(String phoneNumber, String message)
    3. {
    4. String SENT = [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"SMS_SENT"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];
    5. String DELIVERED = [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"SMS_DELIVERED"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];
    6.  
    7. PendingIntent sentPI = PendingIntent.[I]getBroadcast[/I]([/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]this[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], 0,[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Intent(SENT), 0);
    8.  
    9. PendingIntent deliveredPI = PendingIntent.[I]getBroadcast[/I]([/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]this[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], 0,[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Intent(DELIVERED), 0);
    10.  
    11. [/SIZE][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]//---when the SMS has been sent---  [COLOR=red]Following line throws Exception (it is line no 98[/COLOR][/LEFT]
    12. [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT]registerReceiver([/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] BroadcastReceiver(){
    13.  
    14. [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] onReceive(Context arg0, Intent arg1)
    15. {
    16. [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]switch[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] (getResultCode())
    17. {
    18. [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]case[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Activity.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]RESULT_OK[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]:
    19. Toast.[I]makeText[/I](getBaseContext(), [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"SMS Sent"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2],
    20. Toast.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]LENGTH_SHORT[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]).show();
    21. [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]break[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];
    22. [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]case[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] SmsManager.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]RESULT_ERROR_GENERIC_FAILURE[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]:
    23. Toast.[I]makeText[/I](getBaseContext(), [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"Generic failure"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2],
    24. Toast.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]LENGTH_SHORT[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]).show();
    25. [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]break[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];
    26. [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]case[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] SmsManager.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]RESULT_ERROR_NO_SERVICE[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]:
    27. Toast.[I]makeText[/I](getBaseContext(), [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"No service"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2],
    28. Toast.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]LENGTH_SHORT[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]).show();
    29. [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]break[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];
    30. [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]case[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] SmsManager.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]RESULT_ERROR_NULL_PDU[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]:
    31. Toast.[I]makeText[/I](getBaseContext(), [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"Null PDU"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2],
    32. Toast.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]LENGTH_SHORT[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]).show();
    33. [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]break[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];
    34. [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]case[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] SmsManager.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]RESULT_ERROR_RADIO_OFF[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]:
    35. Toast.[I]makeText[/I](getBaseContext(), [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"Radio off"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2],
    36. Toast.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]LENGTH_SHORT[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]).show();
    37. [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]break[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];
    38. }
    39. }
    40. }, [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] IntentFilter(SENT));
    41.  
    42. [/SIZE][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]//---when the SMS has been delivered---[/LEFT]
    43. [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT]registerReceiver([/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] BroadcastReceiver()
    44. {
    45. [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] onReceive(Context arg0, Intent arg1)
    46. {
    47. [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]switch[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] (getResultCode())
    48. {
    49. [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]case[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Activity.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]RESULT_OK[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]:
    50. Toast.[I]makeText[/I](getBaseContext(), [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"SMS Delivered"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2],Toast.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]LENGTH_SHORT[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]).show();
    51. [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]break[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];
    52. [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]case[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Activity.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]RESULT_CANCELED[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]:
    53. Toast.[I]makeText[/I](getBaseContext(), [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"SMS not delivered"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2],Toast.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]LENGTH_SHORT[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]).show();
    54. [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]break[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];
    55. }
    56. }
    57. },[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] IntentFilter(DELIVERED));
    58.  
    59. SmsManager sms = SmsManager.[I]getDefault[/I]();
    60. sms.sendTextMessage(phoneNumber, [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]null[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], message, sentPI, deliveredPI); [/LEFT]
    61. }
    62. [/SIZE]

    Thanks
     

    Advertisement

Share This Page

Loading...