5

I created an app that calls the onPause() when the back button is pressed.

As following way..

protected void onPause() {
        // TODO Auto-generated method stub
        super.onPause();

        // Notification show in status bar

        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
                this).setSmallIcon(R.drawable.icon).setContentTitle("TNLRadio")
                .setContentText("");
        // Creates an explicit intent for an Activity in your app
        // Intent resultIntent = new Intent(this, MainActivity.class);
        Intent resultIntent = this.getIntent();

        TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
        // Adds the back stack for the Intent (but not the Intent itself)
        stackBuilder.addParentStack(MainActivity.class);
        // Adds the Intent that starts the Activity to the top of the stack
        stackBuilder.addNextIntent(resultIntent);
        PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,
                PendingIntent.FLAG_UPDATE_CURRENT);
        mBuilder.setContentIntent(resultPendingIntent);
        NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        int mId = 0;
        // mId allows you to update the notification later on.
        mNotificationManager.notify(mId, mBuilder.build());

        this.unregisterReceiver(UIStateManager.getInsatance());
        // unregister call listener
        UIStateManager.getInsatance().onPause(this);
    }

I want to do the same things when click the back button ... which is in onBackPress(). I call the onPause() method inside the onBackPress() method.

Then I got the error as follows:

08-28 13:45:34.600: E/AndroidRuntime(14153): FATAL EXCEPTION: main
08-28 13:45:34.600: E/AndroidRuntime(14153): java.lang.IllegalArgumentException: Receiver not registered: com.ironone.streaming.evt.UIStateManager@4153d788
08-28 13:45:34.600: E/AndroidRuntime(14153):    at android.app.LoadedApk.forgetReceiverDispatcher(LoadedApk.java:628)
08-28 13:45:34.600: E/AndroidRuntime(14153):    at android.app.ContextImpl.unregisterReceiver(ContextImpl.java:1130)
08-28 13:45:34.600: E/AndroidRuntime(14153):    at android.content.ContextWrapper.unregisterReceiver(ContextWrapper.java:354)
08-28 13:45:34.600: E/AndroidRuntime(14153):    at com.ironone.streaming.MainActivity.onPause(MainActivity.java:567)
08-28 13:45:34.600: E/AndroidRuntime(14153):    at com.ironone.streaming.MainActivity.onBackPressed(MainActivity.java:866)
08-28 13:45:34.600: E/AndroidRuntime(14153):    at android.app.Activity.onKeyUp(Activity.java:2099)
08-28 13:45:34.600: E/AndroidRuntime(14153):    at android.view.KeyEvent.dispatch(KeyEvent.java:2633)
08-28 13:45:34.600: E/AndroidRuntime(14153):    at android.app.Activity.dispatchKeyEvent(Activity.java:2329)
08-28 13:45:34.600: E/AndroidRuntime(14153):    at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:1957)
08-28 13:45:34.600: E/AndroidRuntime(14153):    at android.view.ViewRootImpl.deliverKeyEventPostIme(ViewRootImpl.java:3546)
08-28 13:45:34.600: E/AndroidRuntime(14153):    at android.view.ViewRootImpl.handleFinishedEvent(ViewRootImpl.java:3519)
08-28 13:45:34.600: E/AndroidRuntime(14153):    at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2603)
08-28 13:45:34.600: E/AndroidRuntime(14153):    at android.os.Handler.dispatchMessage(Handler.java:99)
08-28 13:45:34.600: E/AndroidRuntime(14153):    at android.os.Looper.loop(Looper.java:137)
08-28 13:45:34.600: E/AndroidRuntime(14153):    at android.app.ActivityThread.main(ActivityThread.java:4507)
08-28 13:45:34.600: E/AndroidRuntime(14153):    at java.lang.reflect.Method.invokeNative(Native Method)
08-28 13:45:34.600: E/AndroidRuntime(14153):    at java.lang.reflect.Method.invoke(Method.java:511)
08-28 13:45:34.600: E/AndroidRuntime(14153):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
08-28 13:45:34.600: E/AndroidRuntime(14153):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
08-28 13:45:34.600: E/AndroidRuntime(14153):    at dalvik.system.NativeStart.main(Native Method)

Please help me as soon as possible

Trinimon
  • 13,839
  • 9
  • 44
  • 60
ma34
  • 137
  • 1
  • 2
  • 8

3 Answers3

4

First, completely remove the onBackPressed(). Then, try inserting the following code into your onKeyDown() as follows. (if you don't have a such a method already. Just copy past the following code)

public boolean onKeyDown(int keyCode, KeyEvent event) {

    if(keyCode == KeyEvent.KEYCODE_BACK)
    {
            moveTaskToBack(true);
            return true;
    }

    // your other related codes
}
enadun
  • 3,107
  • 3
  • 31
  • 34
0

Your error is on the line "onBackPressed(MainActivity.java:866)". Use Ctrl+L to go to it and please provide the code onBackpressed() with the line 866.

Moreover your error is "java.lang.IllegalArgumentException: Receiver not registered: " so you either have unregistered too early your listener or did not set up correctly a listener.

Please try to paginate the Error log when you paste it. I personally do this

Edit: thanks @trinimon to have edit the code for you :) & @RiteshGune pour avoir éditer le mien :D

Community
  • 1
  • 1
Poutrathor
  • 1,990
  • 2
  • 20
  • 44
0

Please read the error log carefully, and here's the cause of the exception:

08-28 13:45:34.600: E/AndroidRuntime(14153):    at android.content.ContextWrapper.unregisterReceiver(ContextWrapper.java:354)
08-28 13:45:34.600: E/AndroidRuntime(14153):    at com.ironone.streaming.MainActivity.onPause(MainActivity.java:567)
08-28 13:45:34.600: E/AndroidRuntime(14153):    at com.ironone.streaming.MainActivity.onBackPressed(MainActivity.java:866)

So, the root cause lies in the line 567 in your MainActivity.java file, it seems that the UIStateManager.getInsatance() receiver has already been unregistered (somewhere in your code).

And here's a post that addresses the same problem.

Community
  • 1
  • 1
Void Main
  • 2,241
  • 3
  • 27
  • 36