Update MissionsFragment.java

use another way to get the "Context"
This commit is contained in:
kapodamy 2019-01-18 14:32:28 -03:00
parent c4a5e8dc86
commit 9db272f30e
1 changed files with 10 additions and 10 deletions

View File

@ -43,7 +43,7 @@ public class MissionsFragment extends Fragment {
private MissionAdapter mAdapter; private MissionAdapter mAdapter;
private GridLayoutManager mGridManager; private GridLayoutManager mGridManager;
private LinearLayoutManager mLinearManager; private LinearLayoutManager mLinearManager;
private Context mActivity; private Context mContext;
private DMBinder mBinder; private DMBinder mBinder;
private Bundle mBundle; private Bundle mBundle;
@ -56,7 +56,7 @@ public class MissionsFragment extends Fragment {
mBinder = (DownloadManagerService.DMBinder) binder; mBinder = (DownloadManagerService.DMBinder) binder;
mBinder.clearDownloadNotifications(); mBinder.clearDownloadNotifications();
mAdapter = new MissionAdapter(mActivity, mBinder.getDownloadManager(), mClear, mEmpty); mAdapter = new MissionAdapter(mContext, mBinder.getDownloadManager(), mClear, mEmpty);
mAdapter.deleterLoad(mBundle, getView()); mAdapter.deleterLoad(mBundle, getView());
mBundle = null; mBundle = null;
@ -82,11 +82,11 @@ public class MissionsFragment extends Fragment {
mPrefs = PreferenceManager.getDefaultSharedPreferences(getActivity()); mPrefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
mLinear = mPrefs.getBoolean("linear", false); mLinear = mPrefs.getBoolean("linear", false);
mActivity = getActivity(); //mContext = getActivity().getApplicationContext();
mBundle = savedInstanceState; mBundle = savedInstanceState;
// Bind the service // Bind the service
mActivity.bindService(new Intent(mActivity, DownloadManagerService.class), mConnection, Context.BIND_AUTO_CREATE); mContext.bindService(new Intent(mContext, DownloadManagerService.class), mConnection, Context.BIND_AUTO_CREATE);
// Views // Views
mEmpty = v.findViewById(R.id.list_empty_view); mEmpty = v.findViewById(R.id.list_empty_view);
@ -117,13 +117,13 @@ public class MissionsFragment extends Fragment {
* Added in API level 23. * Added in API level 23.
*/ */
@Override @Override
public void onAttach(Context activity) { public void onAttach(Context context) {
super.onAttach(activity); super.onAttach(context);
// Bug: in api< 23 this is never called // Bug: in api< 23 this is never called
// so mActivity=null // so mActivity=null
// so app crashes with null-pointer exception // so app crashes with null-pointer exception
mActivity = activity; mContext = context;
} }
/** /**
@ -134,7 +134,7 @@ public class MissionsFragment extends Fragment {
public void onAttach(Activity activity) { public void onAttach(Activity activity) {
super.onAttach(activity); super.onAttach(activity);
mActivity = activity; mContext = activity.getApplicationContext();
} }
@ -145,7 +145,7 @@ public class MissionsFragment extends Fragment {
mBinder.removeMissionEventListener(mAdapter.getMessenger()); mBinder.removeMissionEventListener(mAdapter.getMessenger());
mBinder.enableNotifications(true); mBinder.enableNotifications(true);
mActivity.unbindService(mConnection); mContext.unbindService(mConnection);
mAdapter.deleterDispose(null); mAdapter.deleterDispose(null);
mBinder = null; mBinder = null;
@ -199,7 +199,7 @@ public class MissionsFragment extends Fragment {
@DrawableRes @DrawableRes
private int getDrawableFromAttribute(@AttrRes int ic) { private int getDrawableFromAttribute(@AttrRes int ic) {
TypedArray styledAttributes = mActivity.obtainStyledAttributes(new int[]{ic}); TypedArray styledAttributes = mContext.obtainStyledAttributes(new int[]{ic});
int resId = styledAttributes.getResourceId(0, -1); int resId = styledAttributes.getResourceId(0, -1);
styledAttributes.recycle(); styledAttributes.recycle();