I have called an AsyncTask
inside my fragment
. I was calling getActivity()
from within doInBackground
of that AsyncTask
, but getActivity
is returning null
.
If I call getActivity
outside from AsyncTask
its working properly, but I need instance of activity
inside my asyncTask
itself.
Any help would be appreciated.. !!!
Pass Activity to AsyncTask method
new Demo().execute(getActivity());
public class Demo extends AsyncTask<Activity,Void,Void>{
Activity activity=null;
@Override
protected Void doInBackground(Activity... params) {
activity=params[0]; //get the activity instance
//Do your task
return null;
}
}