1

我正在使用這個庫loopj/android-async-http在android應用程序中執行網絡操作。在AsyncTask的情況下,當您按下後退按鈕時asynctask正在運行,那麼您可以取消它onBackPressed。我想知道如何在這個圖書館loopj/android-async-http中做到這一點。如何在loopj/android-async-http中處理回按操作http

如果是AsyncTask。我們不喜歡下面

@Override 
public void onBackPressed() { 
    mMyAsyncTask.cancel(true); 
} 

我必須處理這個或循環J/Android的異步HTTP沒有我需要擔心的提前這個

由於自動處理此。

回答

1

我這樣做在片段&它對我來說工作正常。

@Override 
public void onDestroy() { 
    super.onDestroy(); 
    // true specifies that even if the request is active it will be cancelled. 
    if (asyncHttpClient != null) asyncHttpClient.cancelRequests(getActivity(), true); 
}