I have an AsyncTask
to perform a task.I call this from the same class where the AsyncTask
is written and from another class.
I have this statement in the code snippet for fetching user's current location:
GPSTracker gps = new GPSTracker(getActivity());
When called from same class, getActivity()
has value but when called from another class, getActivity()
returns null.
I tried using passing the context through constructor also:
Context mContext;
AsyncDataUpdate(Context context){
this.mContext = context;
}
GPSTracker gps = new GPSTracker(mContext);
which isn't working either. What might be the reason? Any help will be greatly appreciated.