সেভ করা পৃষ্ঠা গুছিয়ে রাখতে 'সংগ্রহ' ব্যবহার করুন
আপনার পছন্দ অনুযায়ী কন্টেন্ট সেভ করুন ও সঠিক বিভাগে রাখুন।
IntentService ক্লাস একটি একক ব্যাকগ্রাউন্ড থ্রেডে একটি অপারেশন চালানোর জন্য একটি সরল কাঠামো প্রদান করে। এটি এটিকে আপনার ইউজার ইন্টারফেসের প্রতিক্রিয়াশীলতাকে প্রভাবিত না করেই দীর্ঘমেয়াদী ক্রিয়াকলাপ পরিচালনা করতে দেয়। এছাড়াও, একটি IntentService বেশিরভাগ ইউজার ইন্টারফেস লাইফসাইকেল ইভেন্ট দ্বারা প্রভাবিত হয় না, তাই এটি এমন পরিস্থিতিতে চলতে থাকে যা একটি AsyncTask বন্ধ করে দেয়
এটি আপনার ব্যবহারকারী ইন্টারফেসের সাথে সরাসরি যোগাযোগ করতে পারে না। এর ফলাফলগুলি UI-তে রাখতে, আপনাকে সেগুলিকে একটি Activity পাঠাতে হবে।
কাজের অনুরোধ ক্রমানুসারে চলে। যদি একটি ক্রিয়াকলাপ একটি IntentService এ চলছে, এবং আপনি এটিকে অন্য একটি অনুরোধ পাঠান, অনুরোধটি প্রথম অপারেশন শেষ না হওয়া পর্যন্ত অপেক্ষা করে৷
একটি IntentService চলমান একটি অপারেশন বাধা দেওয়া যাবে না.
যাইহোক, বেশিরভাগ ক্ষেত্রে একটি IntentService হল সাধারণ ব্যাকগ্রাউন্ড অপারেশন করার জন্য পছন্দের উপায়।
এই নির্দেশিকা আপনাকে নিম্নলিখিত জিনিসগুলি কীভাবে করতে হয় তা দেখায়:
আপনার অ্যাপের জন্য একটি IntentService উপাদান তৈরি করতে, একটি ক্লাস সংজ্ঞায়িত করুন যা IntentService প্রসারিত করে এবং এর মধ্যে, একটি পদ্ধতি সংজ্ঞায়িত করুন যা onHandleIntent() ওভাররাইড করে। যেমন:
কোটলিন
classRSSPullService:IntentService(RSSPullService::class.simpleName)overridefunonHandleIntent(workIntent:Intent){// Gets data from the incoming IntentvaldataString=workIntent.dataString...// Do work here, based on the contents of dataString...}}
জাভা
publicclassRSSPullServiceextendsIntentService{@OverrideprotectedvoidonHandleIntent(IntentworkIntent){// Gets data from the incoming IntentStringdataString=workIntent.getDataString();...// Do work here, based on the contents of dataString...}}
লক্ষ্য করুন যে একটি নিয়মিত Service উপাদানের অন্যান্য কলব্যাক, যেমন onStartCommand() স্বয়ংক্রিয়ভাবে IntentService দ্বারা আহ্বান করা হয়। একটি IntentService এ, আপনার এই কলব্যাকগুলিকে ওভাররাইড করা এড়ানো উচিত৷
একটি IntentService এরও আপনার অ্যাপ্লিকেশন ম্যানিফেস্টে একটি এন্ট্রি প্রয়োজন৷ এই এন্ট্রিটিকে একটি <service> উপাদান হিসেবে প্রদান করুন যা <application> উপাদানের একটি শিশু:
অ্যাট্রিবিউট android:nameIntentService এর ক্লাসের নাম নির্দিষ্ট করে।
লক্ষ্য করুন যে <service> উপাদানটিতে একটি অভিপ্রায় ফিল্টার নেই। যে Activity পরিষেবাতে কাজের অনুরোধ পাঠায় সেটি একটি স্পষ্ট Intent ব্যবহার করে, তাই কোনও ফিল্টারের প্রয়োজন নেই৷ এর মানে হল যে শুধুমাত্র একই অ্যাপের উপাদান বা একই ব্যবহারকারী আইডি সহ অন্যান্য অ্যাপ্লিকেশনগুলি পরিষেবাটি অ্যাক্সেস করতে পারে৷
এই পৃষ্ঠার কন্টেন্ট ও কোডের নমুনাগুলি Content License-এ বর্ণিত লাইসেন্সের অধীনস্থ। Java এবং OpenJDK হল Oracle এবং/অথবা তার অ্যাফিলিয়েট সংস্থার রেজিস্টার্ড ট্রেডমার্ক।
2025-07-29 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-29 UTC-তে শেষবার আপডেট করা হয়েছে।"],[],[],null,["# Create a background service\n\n| **Note:** `IntentService` will not work correctly when the application is in the background on the latest versions of Android. This page is left here as reference for legacy apps only. See the [guide to background processing\n| on Android](/guide/background) for recommended solutions.\n\n\nThe [IntentService](/reference/android/app/IntentService) class provides a straightforward structure for running\nan operation on a single background thread. This allows it to handle long-running operations\nwithout affecting your user interface's responsiveness. Also, an\n[IntentService](/reference/android/app/IntentService) isn't affected by most user interface lifecycle events, so it\ncontinues to run in circumstances that would shut down an [AsyncTask](/reference/android/os/AsyncTask)\n\n\nAn [IntentService](/reference/android/app/IntentService) has a few limitations:\n\n- It can't interact directly with your user interface. To put its results in the UI, you have to send them to an [Activity](/reference/android/app/Activity).\n- Work requests run sequentially. If an operation is running in an [IntentService](/reference/android/app/IntentService), and you send it another request, the request waits until the first operation is finished.\n- An operation running on an [IntentService](/reference/android/app/IntentService) can't be interrupted.\n\n\nHowever, in most cases an [IntentService](/reference/android/app/IntentService) is the preferred way to perform\nsimple background operations.\n\n\nThis guide shows you how to do the following things:\n\n- Create your own subclass of [IntentService](/reference/android/app/IntentService).\n- Create the required callback method [onHandleIntent()](/reference/android/app/IntentService#onHandleIntent(android.content.Intent)).\n- Define the [IntentService](/reference/android/app/IntentService) in your manifest file.\n\nHandle incoming intents\n-----------------------\n\n\nTo create an [IntentService](/reference/android/app/IntentService) component for your app, define a class that\nextends [IntentService](/reference/android/app/IntentService), and within it, define a method that\noverrides [onHandleIntent()](/reference/android/app/IntentService#onHandleIntent(android.content.Intent)). For example: \n\n### Kotlin\n\n```kotlin\nclass RSSPullService : IntentService(RSSPullService::class.simpleName)\n\n override fun onHandleIntent(workIntent: Intent) {\n // Gets data from the incoming Intent\n val dataString = workIntent.dataString\n ...\n // Do work here, based on the contents of dataString\n ...\n }\n}\n```\n\n### Java\n\n```java\npublic class RSSPullService extends IntentService {\n @Override\n protected void onHandleIntent(Intent workIntent) {\n // Gets data from the incoming Intent\n String dataString = workIntent.getDataString();\n ...\n // Do work here, based on the contents of dataString\n ...\n }\n}\n```\n\n\nNotice that the other callbacks of a regular [Service](/reference/android/app/Service) component, such as\n[onStartCommand()](/reference/android/app/Service#onStartCommand(android.content.Intent, int, int)) are automatically invoked by\n[IntentService](/reference/android/app/IntentService). In an [IntentService](/reference/android/app/IntentService), you should avoid\noverriding these callbacks.\n\nTo learn more about creating an `IntentService`, see [Extending the\nIntentService class](/guide/components/services#ExtendingIntentService).\n\nDefine the intent service in the manifest\n-----------------------------------------\n\n\nAn [IntentService](/reference/android/app/IntentService) also needs an entry in your application manifest.\nProvide this entry as a\n[\u003cservice\u003e](/guide/topics/manifest/service-element)\nelement that's a child of the\n[\u003capplication\u003e](/guide/topics/manifest/application-element) element: \n\n```xml\n \u003capplication\n android:icon=\"@drawable/icon\"\n android:label=\"@string/app_name\"\u003e\n ...\n \u003c!--\n Because android:exported is set to \"false\",\n the service is only available to this app.\n --\u003e\n \u003cservice\n android:name=\".RSSPullService\"\n android:exported=\"false\"/\u003e\n ...\n \u003c/application\u003e\n```\n\n\nThe attribute `android:name` specifies the class name of the\n[IntentService](/reference/android/app/IntentService).\n\n\nNotice that the\n[\u003cservice\u003e](/guide/topics/manifest/service-element)\nelement doesn't contain an\n[intent filter](/guide/components/intents-filters). The\n[Activity](/reference/android/app/Activity) that sends work requests to the service uses an\nexplicit [Intent](/reference/android/content/Intent), so no filter is needed. This also\nmeans that only components in the same app or other applications with the\nsame user ID can access the service.\n\n\nNow that you have the basic [IntentService](/reference/android/app/IntentService) class, you can send work requests\nto it with [Intent](/reference/android/content/Intent) objects. The procedure for constructing these objects\nand sending them to your [IntentService](/reference/android/app/IntentService) is described in\n[Send work requests to the background service](/training/run-background-service/send-request)."]]