1

When i put my device in sleep mode (lockscreen), the logcat gets flooded with calls to onPause and onResume this keeps looping and my broadcastreceivers keep getting unregistered and registered, it stops when i go back to the app.

Is this normal?

My Code

@Override
    public void onPause() {
        super.onPause();
        if (getActivity()!= null){
            getActivity().unregisterReceiver(UpdateDataSetBroadCastReceiver);
        }
        Log.i(TAG, "AlbumsFragment OnPause Called!");
    }

    @Override
    public void onResume() {
        super.onResume();
        registerUpdateDataSetBroadCastReceiver();
        Log.i(TAG,"AlbumsFragment OnResume Called!");
    }
Vince VD
  • 1,506
  • 17
  • 38
  • Hey Vince, quick question or two; what device are you testing with, and have you tested with both emulator and physical devices? I'm curious as to whether the behaviour is replicated between the two – Tom Larcher Oct 03 '19 at 04:07
  • What is your Fragment's container? Is it directly within the activity? – Sammy T Oct 03 '19 at 04:17
  • @SammyT Yes and i'm using a viewpager which has 5 fragments. – Vince VD Oct 03 '19 at 04:18
  • @TomLarcher Happens on both – Vince VD Oct 03 '19 at 04:19
  • 1
    Nvm just tested it and not happening on an emulator, could the cause be my physical device which runs a custom rom? – Vince VD Oct 03 '19 at 04:25
  • @Vince since the issue seems to affect physical devices only, I'd then rule out your custom rom by testing on another physical device if you have one. While I don't think it's a wakelock causing this issue for you, I suspect there might be something waking your app when default behaviour would be for it to sleep (and hence a normal flow Activity Lifecycle events) – Tom Larcher Oct 03 '19 at 04:43

1 Answers1

0

In onPause method you should first unregister recievers, call other methods (for example Log.i) and afterwards call super.onPause().

Csongi77
  • 329
  • 3
  • 13