0

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.

Jas
  • 3,207
  • 2
  • 15
  • 45

1 Answers1

1

Use mContext variable after calling of AsyncDataUpdate class constructor as:

GPSTracker gp;
Context mContext;
private AsyncDataUpdate(Context context){
     this.mContext = context;
     this.gps = new GPSTracker(this.mContext);
}
ρяσѕρєя K
  • 132,198
  • 53
  • 198
  • 213