Cronet 요청 수명 주기
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
Cronet을 사용하여 생성된 요청의 수명 주기와 라이브러리에서 제공하는 콜백 메서드를 사용하여 요청을 관리하는 방법을 알아봅니다.
수명 주기 개요
Cronet 라이브러리를 사용하여 생성된 네트워크 요청은 UrlRequest
클래스로 표시됩니다.
다음 개념은 UrlRequest
수명 주기를 이해하는 데 중요합니다.
- 상태
- 상태란 특정 시간에 요청이 놓여 있는 특별한 조건을 말합니다.
Cronet 라이브러리를 사용하여 생성된 UrlRequest 객체는 수명 주기의 여러 상태를 거칩니다. 요청 수명 주기에는 초기 상태와 여러 전환 및 최종 상태가 포함됩니다.
UrlRequest
메서드
- 클라이언트는 상태에 따라
UrlRequest
객체의 특정 메서드를 호출할 수 있습니다. 메서드는 한 상태에서 다른 상태로 요청을 이동합니다.
Callback
메서드
UrlRequest.Callback
클래스의 메서드를 구현하면 앱에서 요청 진행 상황에 관한 업데이트를 수신할 수 있습니다. 콜백 메서드를 구현하여 수명 주기를 한 상태에서 다른 상태로 전환하는 UrlRequest
객체의 메서드를 호출할 수 있습니다.
다음 목록은 UrlRequest
수명 주기의 흐름을 설명합니다.
- 앱에서
start()
메서드를 호출한 후 수명 주기는 Started(시작됨) 상태입니다.
- 서버는 리디렉션 응답을 보낼 수 있으며, 이 응답은
onRedirectReceived()
메서드로 이동합니다. 이 메서드에서는 다음 클라이언트 작업 중 하나를 수행할 수 있습니다.
- 앱이 모든 리디렉션을 따른 후에는 서버가 응답 헤더를 전송하고
onResponseStarted()
메서드가 호출됩니다. 요청은 Waiting for read() 상태가 됩니다. 앱은 read()
메서드를 호출하여 응답 본문의 일부를 읽어야 합니다. read()
가 호출된 후에는 요청이 읽기 상태가 되며, 다음과 같은 결과가 발생할 수 있습니다.
- 읽기 작업이 성공했지만 사용 가능한 데이터가 더 있습니다.
onReadCompleted()
가 호출되고 요청이 다시 Waiting for read() 상태가 됩니다.
응답 본문을 계속 읽으려면 앱이 read()
메서드를 다시 호출해야 합니다. 앱에서 cancel()
메서드를 사용하여 요청 읽기를 중지할 수도 있습니다 .
- 읽기 작업이 성공했으며 사용 가능한 추가 데이터가 없습니다.
onSucceeded()
메서드가 호출되고 요청이 이제 성공 최종 상태가 됩니다.
- 읽기 작업이 실패했습니다.
onFailed
메서드가 호출되고 요청의 최종 상태가 이제 Failed가 됩니다.
다음 다이어그램은 UrlRequest
객체의 수명 주기를
보여줍니다.

Cronet 요청 수명 주기
범례 |
|
초기 상태 |
최종 상태 |
전환 상태 |
콜백 메서드 |
UrlRequest 메서드 |
|
이 페이지에 나와 있는 콘텐츠와 코드 샘플에는 콘텐츠 라이선스에서 설명하는 라이선스가 적용됩니다. 자바 및 OpenJDK는 Oracle 및 Oracle 계열사의 상표 또는 등록 상표입니다.
최종 업데이트: 2025-07-27(UTC)
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["필요한 정보가 없음","missingTheInformationINeed","thumb-down"],["너무 복잡함/단계 수가 너무 많음","tooComplicatedTooManySteps","thumb-down"],["오래됨","outOfDate","thumb-down"],["번역 문제","translationIssue","thumb-down"],["샘플/코드 문제","samplesCodeIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-07-27(UTC)"],[],[],null,["# Cronet request lifecycle\n\nLearn about the lifecycle of requests created using Cronet and how to manage\nthem using the callback methods provided by the library.\n\nLifecycle overview\n------------------\n\nNetwork requests created using the Cronet Library are represented by the\n[`UrlRequest`](/develop/connectivity/cronet/reference/org/chromium/net/UrlRequest) class.\nThe following concepts are important to understand the\n[`UrlRequest`](/develop/connectivity/cronet/reference/org/chromium/net/UrlRequest) lifecycle:\n\n**States**\n: A state is the particular condition that the request is in at a specific time.\n [UrlRequest](/develop/connectivity/cronet/reference/org/chromium/net/UrlRequest) objects created using the Cronet\n Library move through different states in their lifecycle. The request\n lifecycle includes an initial state, and multiple transitional and final\n states.\n\n**`UrlRequest` methods**\n: Clients can call specific methods on\n [`UrlRequest`](/develop/connectivity/cronet/reference/org/chromium/net/UrlRequest) objects depending on the\n state. The methods move the request from one state to another.\n\n**`Callback` methods**\n: By implementing methods of the\n [`UrlRequest.Callback`](/develop/connectivity/cronet/reference/org/chromium/net/UrlRequest.Callback) class, your\n app can receive updates about the progress of the request. You can implement\n the callback methods to call methods of the\n [`UrlRequest`](/develop/connectivity/cronet/reference/org/chromium/net/UrlRequest) object that take the lifecycle\n from a state to another.\n\nThe following list describes the flow of the\n[`UrlRequest`](/develop/connectivity/cronet/reference/org/chromium/net/UrlRequest) lifecycle:\n\n1. The lifecycle is in the **Started** state after your app calls the [`start()`](/develop/connectivity/cronet/reference/org/chromium/net/UrlRequest#start()) method.\n2. The server could send a redirect response, which takes the flow to the [`onRedirectReceived()`](/develop/connectivity/cronet/reference/org/chromium/net/UrlRequest.Callback#onRedirectReceived(org.chromium.net.UrlRequest,%20org.chromium.net.UrlResponseInfo,%20java.lang.String)) method. In this method, you can take one of the following client actions:\n - Follow the redirect using [`followRedirect()`](/develop/connectivity/cronet/reference/org/chromium/net/UrlRequest#followRedirect()). This method takes the request back to the **Started** state.\n - Cancel the request using [`cancel()`](/develop/connectivity/cronet/reference/org/chromium/net/UrlRequest#cancel()). This method takes the request to the [`onCanceled()`](/develop/connectivity/cronet/reference/org/chromium/net/UrlRequest.Callback#onCanceled(org.chromium.net.UrlRequest,%20org.chromium.net.UrlResponseInfo)) method where the app can perform additional operations before the request is moved to the **Canceled** final state.\n3. After the app follows all the redirects, the server sends the response headers and the [`onResponseStarted()`](/develop/connectivity/cronet/reference/org/chromium/net/UrlRequest.Callback#onResponseStarted(org.chromium.net.UrlRequest,%20org.chromium.net.UrlResponseInfo)) method is called. The request is in the **Waiting for read()** state. The app should call the [`read()`](/develop/connectivity/cronet/reference/org/chromium/net/UrlRequest#read(java.nio.ByteBuffer)) method to attempt to read part of the response body. After `read()` is called, the request is in the **Reading** state, where there are the following possible outcomes:\n - The reading action was successful, but there is more data available. The [`onReadCompleted()`](/develop/connectivity/cronet/reference/org/chromium/net/UrlRequest.Callback#onReadCompleted(org.chromium.net.UrlRequest,%20org.chromium.net.UrlResponseInfo,%20java.nio.ByteBuffer)) is called and the request is in the **Waiting for read()** state again. The app should call the [`read()`](/develop/connectivity/cronet/reference/org/chromium/net/UrlRequest#read(java.nio.ByteBuffer)) method again to continue reading the response body. The app could also stop reading the request by using the [`cancel()`](/develop/connectivity/cronet/reference/org/chromium/net/UrlRequest#cancel()) method .\n - The reading action was successful, and there is no more data available. The [`onSucceeded()`](/develop/connectivity/cronet/reference/org/chromium/net/UrlRequest.Callback#onSucceeded(org.chromium.net.UrlRequest,%20org.chromium.net.UrlResponseInfo)) method is called and the request is now in the **Succeeded** final state.\n - The reading action failed. The [`onFailed`](/develop/connectivity/cronet/reference/org/chromium/net/UrlRequest.Callback#onFailed(org.chromium.net.UrlRequest,%20org.chromium.net.UrlResponseInfo,%20org.chromium.net.CronetException)) method is called and the final state of the request is now **Failed**.\n\nThe following diagram shows the lifecycle of a\n[`UrlRequest`](/develop/connectivity/cronet/reference/org/chromium/net/UrlRequest) object:\n\n\u003cbr /\u003e\n\n\nThe Cronet request lifecycle\n\n| Legend | |\n|----------------------|------------------|\n| initial state | final state |\n| transitional state | callback methods |\n| `UrlRequest` methods | |"]]