ব্যাকগ্রাউন্ড সার্ভিসে কাজের অনুরোধ পাঠান
সেভ করা পৃষ্ঠা গুছিয়ে রাখতে 'সংগ্রহ' ব্যবহার করুন
আপনার পছন্দ অনুযায়ী কন্টেন্ট সেভ করুন ও সঠিক বিভাগে রাখুন।
আগের পাঠে দেখানো হয়েছে কিভাবে একটি JobIntentService
ক্লাস তৈরি করতে হয়। এই পাঠটি আপনাকে দেখায় যে কিভাবে একটি Intent
সাথে কাজ সারিবদ্ধ করে একটি অপারেশন চালানোর জন্য JobIntentService
ট্রিগার করতে হয়। এই Intent
ঐচ্ছিকভাবে JobIntentService
প্রক্রিয়া করার জন্য ডেটা থাকতে পারে।
একটি কাজের অনুরোধ তৈরি করুন এবং একটি JobIntentService-এ পাঠান
একটি কাজের অনুরোধ তৈরি করতে এবং এটি একটি JobIntentService
এ পাঠাতে, একটি Intent
তৈরি করুন এবং enqueueWork()
কল করে এটি কার্যকর করার জন্য সারিবদ্ধ করুন। ঐচ্ছিকভাবে আপনি JobIntentService প্রক্রিয়া করার জন্য উদ্দেশ্য (ইন্টেন্ট অতিরিক্ত আকারে) ডেটা যোগ করতে পারেন। ইন্টেন্ট তৈরি করার বিষয়ে আরও তথ্যের জন্য, ইন্টেন্টস এবং ইনটেন্ট ফিল্টারে একটি ইন্টেন্ট তৈরি করা বিভাগটি পড়ুন
নিম্নলিখিত কোড স্নিপেটগুলি এই প্রক্রিয়াটি প্রদর্শন করে:
-
RSSPullService
নামক JobIntentService
এর জন্য একটি নতুন Intent
তৈরি করুন।
কোটলিন
/*
* Creates a new Intent to start the RSSPullService
* JobIntentService. Passes a URI in the
* Intent's "data" field.
*/
serviceIntent = Intent().apply {
putExtra("download_url", dataUrl)
}
জাভা
/*
* Creates a new Intent to start the RSSPullService
* JobIntentService. Passes a URI in the
* Intent's "data" field.
*/
serviceIntent = new Intent();
serviceIntent.putExtra("download_url", dataUrl));
- কল
enqueueWork()
কোটলিন
private const val RSS_JOB_ID = 1000
RSSPullService.enqueueWork(context, RSSPullService::class.java, RSS_JOB_ID, serviceIntent)
জাভা
// Starts the JobIntentService
private static final int RSS_JOB_ID = 1000;
RSSPullService.enqueueWork(getContext(), RSSPullService.class, RSS_JOB_ID, serviceIntent);
লক্ষ্য করুন যে আপনি একটি কার্যকলাপ বা খণ্ডের যেকোনো জায়গা থেকে কাজের অনুরোধ পাঠাতে পারেন। উদাহরণস্বরূপ, যদি আপনাকে প্রথমে ব্যবহারকারীর ইনপুট পেতে হয়, আপনি একটি কলব্যাক থেকে অনুরোধ পাঠাতে পারেন যা একটি বোতাম ক্লিক বা অনুরূপ অঙ্গভঙ্গিতে সাড়া দেয়।
একবার আপনি enqueueWork()
কে কল করলে, JobIntentService
তার onHandleWork()
পদ্ধতিতে সংজ্ঞায়িত কাজটি করে এবং তারপর নিজেই বন্ধ হয়ে যায়।
পরবর্তী পদক্ষেপটি হল কাজের অনুরোধের ফলাফলগুলিকে মূল কার্যকলাপ বা খণ্ডে রিপোর্ট করা। পরবর্তী পাঠ আপনাকে দেখায় কিভাবে একটি BroadcastReceiver
দিয়ে এটি করতে হয়।
এই পৃষ্ঠার কন্টেন্ট ও কোডের নমুনাগুলি 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,["# Send work requests to the background service\n\n| **Note:** This page is left here as reference for legacy apps only. See the [guide to background processing on Android](/guide/background) for recommended solutions.\n\n\nThe previous lesson showed you how to create a\n[`JobIntentService`](/reference/androidx/core/app/JobIntentService) class. This\nlesson shows you how to trigger the\n[`JobIntentService`](/reference/androidx/core/app/JobIntentService) to run an operation by\nenqueuing work with an [`Intent`](/reference/android/content/Intent).\nThis [`Intent`](/reference/android/content/Intent) can\noptionally contain data for the\n[`JobIntentService`](/reference/androidx/core/app/JobIntentService) to process.\n\nCreate and send a work request to a JobIntentService\n----------------------------------------------------\n\n\nTo create a work request and send it to a\n[`JobIntentService`](/reference/androidx/core/app/JobIntentService),\ncreate an [`Intent`](/reference/android/content/Intent) and enqueue it to\nbe executed by calling [`enqueueWork()`](/reference/androidx/core/app/JobIntentService#enqueuework).\nOptionally you can add data to the intent (in the form of intent extras) for the\nJobIntentService to process. For more information about creating intents, read the Building an\nintent section in [Intents and Intent Filters](/guide/components/intents-filters)\n\n\nThe following code snippets demonstrate this process:\n\n1. Create a new [`Intent`](/reference/android/content/Intent) for the [`JobIntentService`](/reference/androidx/core/app/JobIntentService) called `RSSPullService`. \n\n ### Kotlin\n\n ```kotlin\n /*\n * Creates a new Intent to start the RSSPullService\n * JobIntentService. Passes a URI in the\n * Intent's \"data\" field.\n */\n serviceIntent = Intent().apply {\n putExtra(\"download_url\", dataUrl)\n }\n ```\n\n ### Java\n\n ```java\n /*\n * Creates a new Intent to start the RSSPullService\n * JobIntentService. Passes a URI in the\n * Intent's \"data\" field.\n */\n serviceIntent = new Intent();\n serviceIntent.putExtra(\"download_url\", dataUrl));\n ```\n2. Call [`enqueueWork()`](/reference/androidx/core/app/JobIntentService#enqueuework) \n\n ### Kotlin\n\n ```kotlin\n private const val RSS_JOB_ID = 1000\n RSSPullService.enqueueWork(context, RSSPullService::class.java, RSS_JOB_ID, serviceIntent)\n ```\n\n ### Java\n\n ```java\n // Starts the JobIntentService\n private static final int RSS_JOB_ID = 1000;\n RSSPullService.enqueueWork(getContext(), RSSPullService.class, RSS_JOB_ID, serviceIntent);\n ```\n\n\nNotice that you can send the work request from anywhere in an Activity or Fragment.\nFor example, if you need to get user input first, you can send the request from a callback\nthat responds to a button click or similar gesture.\n\n\nOnce you call [`enqueueWork()`](/reference/androidx/core/app/JobIntentService#enqueuework),\nthe [`JobIntentService`](/reference/androidx/core/app/JobIntentService) does the work defined in its\n[`onHandleWork()`](/reference/androidx/core/app/JobIntentService#onHandleWork) method, and then stops itself.\n\n\nThe next step is to report the results of the work request back to the originating Activity\nor Fragment. The next lesson shows you how to do this with a\n[BroadcastReceiver](/reference/android/content/BroadcastReceiver)."]]