From e869098434e30be4d46612908f14d37358a3be34 Mon Sep 17 00:00:00 2001 From: k3b Date: Thu, 2 Feb 2017 01:58:47 +0100 Subject: [PATCH] fix NullPointerExcpeption when opening "Downloads" with android-api < 23 --- .../giga/ui/fragment/MissionsFragment.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/us/shandian/giga/ui/fragment/MissionsFragment.java b/app/src/main/java/us/shandian/giga/ui/fragment/MissionsFragment.java index 43b85a2b5..793876756 100644 --- a/app/src/main/java/us/shandian/giga/ui/fragment/MissionsFragment.java +++ b/app/src/main/java/us/shandian/giga/ui/fragment/MissionsFragment.java @@ -84,9 +84,23 @@ public abstract class MissionsFragment extends Fragment return v; } - @Override + /** Added in API level 23. */ + @Override public void onAttach(Context activity) { super.onAttach(activity); + + // Bug: in api< 23 this is never called + // so mActivity=null + // so app crashes with nullpointer exception + mActivity = activity; + } + + /** deprecated in API level 23, + * but must remain to allow compatibility with api<23 */ + @Override + public void onAttach(Activity activity) { + super.onAttach(activity); + mActivity = activity; }