Issue
Previous I haved that AsyncTask on main activity and called with:
new SyncGetLocations(ActivityMain.this).execute();
Now,I move it to a fragment and don't know now how to call it from MainActivity
.
AsyncTask look alike :
private static class SyncGetLocations extends AsyncTask<Void, Void, Void> {
private WeakReference<ActivityMap> activityReference;
SyncGetLocations(ActivityMap context) {
activityReference = new WeakReference<>(context);
}
@Override
protected void onPreExecute() {
}
@Override
protected Void doInBackground(Void... voids) {
}
@Override
protected void onPostExecute(Void aVoid) {
}
}
Solution
Either
From MainActivity find your fragment:
val fragment = getSupportFragmentManager().findFragmentByTag(...) or findFragmentByID(...)
and then call a method in this fragment to launch the asyncTask
fragent.callAsyncTask()
Or
make your asynctask public or remove it from fragment to be its own class and call it froim every where you want
I suggest you to make asyntask not an inner class of fragment of activity it you wants to call it from everywhere
Answered By - SebastienRieu
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.