Kiwix-android: Unregister the receiver when fragment is destroyed. Refactor code.

Created on 2 Mar 2018  路  10Comments  路  Source: kiwix/kiwix-android

Is it a ?

  • [x] Bug Report

  • [ ] Feature Request

Bug Report

Step 1: Are you ready to report?

  • Your issue may already be reported! Please search on the issue track before creating one.
  • [x] I have tested with the last (dev) version of the software. ( If not, and if possible, run your test again with the most recent version available.)

Step 2: What is your environment?

  • version of the software you use : Commit bea032c
  • device / operating system : Android (Sony Z5)

Step 3: Describe the problem:

  • What do you obtain? A copy of the error message or a screenshot is always useful.
  • When does this occur?
    When the fragment LibraryFragment destroy it view.

    Steps to reproduce:

  • Got to "Get Content"

  • Rotate device screen
  • See the error in the Android Studio log
    ...

  • What should be the behaviour from your point of view? How do you expect the service to work?
    Should not be an error in the log.

Step 4 (optional) : Other Comments:

  • What is the context of this ticket? If not obvious, explain why you need to do this.

  • If you have an idea about the technical background of the ticket, please share it.
    To correct this we just need to unregister the broadcast receiver when the fragment calls the destroy method. I have worked in that and I sent the PR #545. Sorry to send it to a wrong branch, next time I will send the PR to master. In the PR I did also a little refactor in LibraryAdapter to reduce the lines with a common method to set the text into TextViews.

bug good first issue

Most helpful comment

We should fix this. When the issue template asks for a "copy or a screenshot" it means that you copy a crash log or screenshot the application. Not screenshot the log :P.

All 10 comments

We should fix this. When the issue template asks for a "copy or a screenshot" it means that you copy a crash log or screenshot the application. Not screenshot the log :P.

Ups... Hahaha. Actually the applicattions doesn't crash but is better prevent future problems with that. As you can see in the PR, I removed code from ZimManageActivity where in theory the app unregister the reciver, but it really didn't do that because the code should be in the fragment itself. Do you agree?

Log:

03-03 18:10:15.473 17580-17580/org.kiwix.kiwixmobile E/ActivityThread: Activity org.kiwix.kiwixmobile.zim_manager.ZimManageActivity has leaked IntentReceiver org.kiwix.kiwixmobile.zim_manager.library_view.LibraryFragment$NetworkBroadcastReceiver@3dc529ad that was originally registered here. Are you missing a call to unregisterReceiver()?
                                                                       android.app.IntentReceiverLeaked: Activity org.kiwix.kiwixmobile.zim_manager.ZimManageActivity has leaked IntentReceiver org.kiwix.kiwixmobile.zim_manager.library_view.LibraryFragment$NetworkBroadcastReceiver@3dc529ad that was originally registered here. Are you missing a call to unregisterReceiver()?
                                                                           at android.app.LoadedApk$ReceiverDispatcher.<init>(LoadedApk.java:963)
                                                                           at android.app.LoadedApk.getReceiverDispatcher(LoadedApk.java:720)
                                                                           at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1679)
                                                                           at android.app.ContextImpl.registerReceiver(ContextImpl.java:1659)
                                                                           at android.app.ContextImpl.registerReceiver(ContextImpl.java:1653)
                                                                           at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:500)
                                                                           at org.kiwix.kiwixmobile.zim_manager.library_view.LibraryFragment.onCreateView(LibraryFragment.java:137)
                                                                           at android.support.v4.app.Fragment.performCreateView(Fragment.java:2261)
                                                                           at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1419)
                                                                           at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1750)
                                                                           at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1819)
                                                                           at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:797)
                                                                           at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2590)
                                                                           at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2377)
                                                                           at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2332)
                                                                           at android.support.v4.app.FragmentManagerImpl.execSingleAction(FragmentManager.java:2209)
                                                                           at android.support.v4.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:649)
                                                                           at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:145)
                                                                           at android.support.v4.view.ViewPager.populate(ViewPager.java:1238)
                                                                           at android.support.v4.view.ViewPager.populate(ViewPager.java:1086)
                                                                           at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1616)
                                                                           at android.view.View.measure(View.java:17573)
                                                                           at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5547)
                                                                           at android.support.design.widget.CoordinatorLayout.onMeasureChild(CoordinatorLayout.java:719)
                                                                           at android.support.design.widget.HeaderScrollingViewBehavior.onMeasureChild(HeaderScrollingViewBehavior.java:91)
                                                                           at android.support.design.widget.AppBarLayout$ScrollingViewBehavior.onMeasureChild(AppBarLayout.java:1361)
                                                                           at android.support.design.widget.CoordinatorLayout.onMeasure(CoordinatorLayout.java:789)
                                                                           at android.view.View.measure(View.java:17573)
                                                                           at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5547)
                                                                           at android.widget.FrameLayout.onMeasure(FrameLayout.java:436)
                                                                           at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:139)
                                                                           at android.view.View.measure(View.java:17573)
                                                                           at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5547)
                                                                           at android.widget.FrameLayout.onMeasure(FrameLayout.java:436)
                                                                           at android.view.View.measure(View.java:17573)
                                                                           at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5547)
                                                                           at android.widget.FrameLayout.onMeasure(FrameLayout.java:436)
                                                                           at android.view.View.measure(View.java:17573)
                                                                           at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5547)
                                                                           at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1436)
                                                                           at android.widget.LinearLayout.measureVertical(LinearLayout.java:722)
                                                                           at android.widget.LinearLayout.onMeasure(LinearLayout.java:613)
                                                                           at android.view.View.measure(View.java:17573)
                                                                           at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5547)
                                                                           at android.widget.FrameLayout.onMeasure(FrameLayout.java:436)
                                                                        at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(Phone

@amerinoo

I removed code from ZimManageActivity where in theory the app unregister the reciver, but it really didn't do that because the code should be in the fragment itself. Do you agree?

I kind of disagree but you're on the right track. It does do what it is supposed to do but it does it when the Activity is finished not the fragment. Hence we get the crash.
Your PR seems correct though since you have moved it to the onDestroyView of the Fragment.

Have you already get the crash? It's so strange. Could you tell us the steps to reproduce the crash?

Sorry, by crash i meant the error log. The app doesn't crash.
Also this isn't from your PR. You added the screenshot for the error which is difficult to read hence i added the log message from the master branch.

Now it's all ok I think, isn't it?

Yup

@macgills You have closed the PR, saying this was fixed in 2.5. But the linked ticket has remained open. Could you please confirm/close here too?

My mistake, yes I confirm this is not a problem, closing

Was this page helpful?
0 / 5 - 0 ratings

Related issues

yashk2000 picture yashk2000  路  5Comments

brijeshshah13 picture brijeshshah13  路  4Comments

brijeshshah13 picture brijeshshah13  路  4Comments

siddharth2010 picture siddharth2010  路  4Comments

RaiLokesh picture RaiLokesh  路  4Comments