Stop AsyncTask in Fragments when Back Button is pressed

前端 未结 5 1544
别跟我提以往
别跟我提以往 2021-01-17 01:17

i have an activities that host fragments. pressing a button goes from fragment A to fragment B through a FragmentTransaction and the added to the back stack. Now fragment B

5条回答
  •  天命终不由人
    2021-01-17 01:41

        AsyncTaskRunner doAsynchronousTask; //Before onCreateView
    
    //in onCreateView() 
        doAsynchronousTask = new AsyncTaskRunner();``
        doAsynchronousTask.execute();
    
    
    // after  onCreateView()
        @Override
        public void onStop() {
            super.onStop();
            doAsynchronousTask.cancel(true);
        }
    

提交回复
热议问题