Cronet অনুরোধ জীবনচক্র
সেভ করা পৃষ্ঠা গুছিয়ে রাখতে 'সংগ্রহ' ব্যবহার করুন
আপনার পছন্দ অনুযায়ী কন্টেন্ট সেভ করুন ও সঠিক বিভাগে রাখুন।
Cronet ব্যবহার করে তৈরি করা অনুরোধের জীবনচক্র এবং লাইব্রেরি দ্বারা প্রদত্ত কলব্যাক পদ্ধতিগুলি ব্যবহার করে কীভাবে সেগুলি পরিচালনা করা যায় সে সম্পর্কে জানুন।
জীবনচক্র ওভারভিউ
Cronet লাইব্রেরি ব্যবহার করে তৈরি করা নেটওয়ার্ক অনুরোধ UrlRequest
ক্লাস দ্বারা প্রতিনিধিত্ব করা হয়। UrlRequest
জীবনচক্র বোঝার জন্য নিম্নলিখিত ধারণাগুলি গুরুত্বপূর্ণ:
- রাজ্যগুলি
- একটি রাষ্ট্র হল একটি নির্দিষ্ট অবস্থা যেখানে অনুরোধ একটি নির্দিষ্ট সময়ে হয়। ক্রোনেট লাইব্রেরি ব্যবহার করে তৈরি করা UrlRequest বস্তুগুলি তাদের জীবনচক্রে বিভিন্ন রাজ্যের মধ্য দিয়ে যায়। অনুরোধের জীবনচক্রে একটি প্রাথমিক অবস্থা এবং একাধিক ক্রান্তিকালীন এবং চূড়ান্ত অবস্থা অন্তর্ভুক্ত রয়েছে।
-
UrlRequest
পদ্ধতি - ক্লায়েন্টরা রাষ্ট্রের উপর নির্ভর করে
UrlRequest
অবজেক্টে নির্দিষ্ট পদ্ধতিতে কল করতে পারে। পদ্ধতিগুলি অনুরোধটিকে এক রাজ্য থেকে অন্য রাজ্যে নিয়ে যায়। -
Callback
পদ্ধতি -
UrlRequest.Callback
ক্লাসের পদ্ধতি প্রয়োগ করে, আপনার অ্যাপ অনুরোধের অগ্রগতি সম্পর্কে আপডেট পেতে পারে। আপনি UrlRequest
অবজেক্টের কল পদ্ধতিতে কলব্যাক পদ্ধতি প্রয়োগ করতে পারেন যা জীবনচক্রকে একটি রাজ্য থেকে অন্য রাজ্যে নিয়ে যায়।
নিম্নলিখিত তালিকাটি UrlRequest
জীবনচক্রের প্রবাহ বর্ণনা করে:
- আপনার অ্যাপ
start()
পদ্ধতিতে কল করার পরে জীবনচক্রটি স্টার্টেড অবস্থায় থাকে। - সার্ভার একটি পুনঃনির্দেশ প্রতিক্রিয়া পাঠাতে পারে, যা
onRedirectReceived()
পদ্ধতিতে প্রবাহকে নিয়ে যায়। এই পদ্ধতিতে, আপনি নিম্নলিখিত ক্লায়েন্ট অ্যাকশনগুলির মধ্যে একটি নিতে পারেন:-
followRedirect()
ব্যবহার করে পুনঃনির্দেশ অনুসরণ করুন। এই পদ্ধতিটি অনুরোধটিকে স্টার্টেড অবস্থায় ফিরিয়ে নিয়ে যায়। -
cancel()
ব্যবহার করে অনুরোধটি বাতিল করুন। এই পদ্ধতিটি অনুরোধটিকে onCanceled()
পদ্ধতিতে নিয়ে যায় যেখানে অনুরোধটি বাতিল চূড়ান্ত অবস্থায় সরানোর আগে অ্যাপটি অতিরিক্ত ক্রিয়াকলাপ সম্পাদন করতে পারে।
- অ্যাপটি সমস্ত পুনঃনির্দেশ অনুসরণ করার পরে, সার্ভার প্রতিক্রিয়া শিরোনাম পাঠায় এবং
onResponseStarted()
পদ্ধতি বলা হয়। অনুরোধটি পড়া () অবস্থায় অপেক্ষা করছে । রেসপন্স বডির অংশ পড়ার চেষ্টা করার জন্য অ্যাপটিকে read()
পদ্ধতিতে কল করা উচিত। read()
কল করার পরে, অনুরোধটি পঠন অবস্থায় থাকে, যেখানে নিম্নলিখিত সম্ভাব্য ফলাফল রয়েছে:- রিডিং অ্যাকশন সফল হয়েছে, কিন্তু আরও ডেটা পাওয়া যাচ্ছে।
onReadCompleted()
বলা হয় এবং রিকোয়েস্টটি আবার Read() অবস্থায় অপেক্ষা করছে । রেসপন্স বডি পড়া চালিয়ে যেতে অ্যাপটিকে পুনরায় read()
পদ্ধতিতে কল করা উচিত। অ্যাপটি cancel()
পদ্ধতি ব্যবহার করে অনুরোধ পড়া বন্ধ করতে পারে। - রিডিং অ্যাকশন সফল হয়েছে, এবং আর কোনো ডেটা উপলব্ধ নেই৷
onSucceeded()
পদ্ধতিটি বলা হয় এবং অনুরোধটি এখন সফল চূড়ান্ত অবস্থায় রয়েছে। - পড়ার ক্রিয়া ব্যর্থ হয়েছে৷
onFailed
পদ্ধতি বলা হয় এবং অনুরোধের চূড়ান্ত অবস্থা এখন ব্যর্থ ।
নিম্নলিখিত চিত্রটি একটি UrlRequest
বস্তুর জীবনচক্র দেখায়:

ক্রনেট অনুরোধ জীবনচক্র
কিংবদন্তি | |
---|
প্রাথমিক অবস্থা | চূড়ান্ত অবস্থা |
ক্রান্তিকালীন অবস্থা | কলব্যাক পদ্ধতি |
UrlRequest পদ্ধতি | |
এই পৃষ্ঠার কন্টেন্ট ও কোডের নমুনাগুলি Content License-এ বর্ণিত লাইসেন্সের অধীনস্থ। Java এবং OpenJDK হল Oracle এবং/অথবা তার অ্যাফিলিয়েট সংস্থার রেজিস্টার্ড ট্রেডমার্ক।
2025-07-29 UTC-তে শেষবার আপডেট করা হয়েছে।
[null,null,["2025-07-29 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 | |"]]