From f09d68ad59196971894ac9156ef65ade115e7d02 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Wed, 3 Jan 2018 20:58:49 +0100 Subject: [PATCH] Check activity != null before drawing graph. --- .../plugins/Overview/OverviewFragment.java | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java index ef10353ec2..ccef69a17b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java @@ -11,6 +11,7 @@ import android.graphics.Paint; import android.os.Bundle; import android.os.Handler; import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentManager; import android.support.v4.content.ContextCompat; import android.support.v7.app.AlertDialog; @@ -1338,20 +1339,23 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, secondGraphData.addNowLine(now); // do GUI update - getActivity().runOnUiThread(new Runnable() { - @Override - public void run() { - if (showIobView.isChecked() || showCobView.isChecked() || showDeviationsView.isChecked() || showRatiosView.isChecked()) { - iobGraph.setVisibility(View.VISIBLE); - } else { - iobGraph.setVisibility(View.GONE); + FragmentActivity activity = getActivity(); + if (activity != null) { + activity.runOnUiThread(new Runnable() { + @Override + public void run() { + if (showIobView.isChecked() || showCobView.isChecked() || showDeviationsView.isChecked() || showRatiosView.isChecked()) { + iobGraph.setVisibility(View.VISIBLE); + } else { + iobGraph.setVisibility(View.GONE); + } + // finally enforce drawing of graphs + graphData.performUpdate(); + secondGraphData.performUpdate(); + Profiler.log(log, from + " - onDataChanged", updateGUIStart); } - // finaly enforce drawing of graphs - graphData.performUpdate(); - secondGraphData.performUpdate(); - Profiler.log(log, from + " - onDataChanged", updateGUIStart); - } - }); + }); + } } }).start();