Put null check around access of R.id.header fragment.

Please note I haven't reproduced the specific problem. Also, the stack
traces being reported are only marginally informative, because they are
in response to a content providers firing events, and thus don't have
any context about when or where the event was fired from.

However, my looking at the code seems to indicate that this will prevent
NPE when the Activity is no longer visible but an app is finished
installing. Also, the view should still update correctly on resuming the
Activity because the `onResumeFragments()` methods will be invoked
which invokes the `refreshHeaders()` method.

Fixes #286.
This commit is contained in:
Peter Serwylo 2016-02-05 22:27:11 +11:00
parent 02c8fac906
commit d9f0c86c2e

View File

@ -609,7 +609,9 @@ public class AppDetails extends AppCompatActivity implements ProgressListener, A
private void refreshHeader() { private void refreshHeader() {
mHeaderFragment = (AppDetailsHeaderFragment) mHeaderFragment = (AppDetailsHeaderFragment)
getSupportFragmentManager().findFragmentById(R.id.header); getSupportFragmentManager().findFragmentById(R.id.header);
mHeaderFragment.updateViews(); if (mHeaderFragment != null) {
mHeaderFragment.updateViews();
}
} }
@Override @Override