इस गाइड में, बैकग्राउंड में चलने वाली सेवा में किए गए काम के अनुरोध की स्थिति की शिकायत करने का तरीका बताया गया है
    उस कॉम्पोनेंट को जिसमें अनुरोध भेजा गया है. उदाहरण के लिए, इसकी मदद से आप
    Activity ऑब्जेक्ट के यूज़र इंटरफ़ेस (यूआई) में अनुरोध. Google को मैसेज भेजने और पाने का
    रिसीव स्टेटस का मतलब LocalBroadcastManager का इस्तेमाल करना है, जो
    यह आपके ऐप्लिकेशन के कॉम्पोनेंट के लिए, Intent ऑब्जेक्ट के ब्रॉडकास्ट को सीमित करता है.
JobIntentService से स्टेटस की रिपोर्ट करें
    काम के अनुरोध की स्थिति को
    JobIntentService से अन्य
    कॉम्पोनेंट, पहले एक Intent बनाएं, जिसमें उसकी
    बढ़ा हुआ डेटा है. विकल्प के तौर पर, इसमें कोई कार्रवाई और डेटा यूआरआई जोड़ा जा सकता है
    Intent.
    इसके बाद, इस नंबर पर कॉल करके Intent भेजें
    LocalBroadcastManager.sendBroadcast(). ऐसा करने से Intent किसी भी
    करने के लिए पंजीकृत किया गया है.
    LocalBroadcastManager का इंस्टेंस पाने के लिए, इस पर कॉल करें
    getInstance().
उदाहरण के लिए:
Kotlin
... // Defines a custom Intent action const val BROADCAST_ACTION = "com.example.android.threadsample.BROADCAST" ... // Defines the key for the status "extra" in an Intent const val EXTENDED_DATA_STATUS = "com.example.android.threadsample.STATUS" ... class RSSPullService : JobIntentService() { ... /* * Creates a new Intent containing a Uri object * BROADCAST_ACTION is a custom Intent action */ val localIntent = Intent(BROADCAST_ACTION).apply { // Puts the status into the Intent putExtra(EXTENDED_DATA_STATUS, status) } // Broadcasts the Intent to receivers in this app. LocalBroadcastManager.getInstance(this).sendBroadcast(localIntent) ... }
Java
public final class Constants { ... // Defines a custom Intent action public static final String BROADCAST_ACTION = "com.example.android.threadsample.BROADCAST"; ... // Defines the key for the status "extra" in an Intent public static final String EXTENDED_DATA_STATUS = "com.example.android.threadsample.STATUS"; ... } public class RSSPullService extends JobIntentService { ... /* * Creates a new Intent containing a Uri object * BROADCAST_ACTION is a custom Intent action */ Intent localIntent = new Intent(Constants.BROADCAST_ACTION) // Puts the status into the Intent .putExtra(Constants.EXTENDED_DATA_STATUS, status); // Broadcasts the Intent to receivers in this app. LocalBroadcastManager.getInstance(this).sendBroadcast(localIntent); ... }
    अगला चरण, आने वाले ब्रॉडकास्ट Intent ऑब्जेक्ट को
    वह कॉम्पोनेंट जिसने मूल काम का अनुरोध भेजा था.
JobIntentService से स्टेटस ब्रॉडकास्ट पाएं
    ब्रॉडकास्ट होने वाले Intent ऑब्जेक्ट पाने के लिए, इसकी सब-क्लास का इस्तेमाल करें
    BroadcastReceiver. सब-क्लास में,
    BroadcastReceiver.onReceive() कॉलबैक
    तरीका, जो LocalBroadcastManager मिलने पर शुरू होता है
    और Intent. LocalBroadcastManager अभी तक किसी भी व्यक्ति ने चेक इन नहीं किया है
    इनकमिंग Intent को पास करता है
    BroadcastReceiver.onReceive().
उदाहरण के लिए:
Kotlin
// Broadcast receiver for receiving status updates from the IntentService. private class DownloadStateReceiver : BroadcastReceiver() { override fun onReceive(context: Context, intent: Intent) { ... /* * Handle Intents here. */ ... } }
Java
// Broadcast receiver for receiving status updates from the IntentService. private class DownloadStateReceiver extends BroadcastReceiver { // Called when the BroadcastReceiver gets an Intent it's registered to receive @Override public void onReceive(Context context, Intent intent) { ... /* * Handle Intents here. */ ... } }
    BroadcastReceiver तय करने के बाद, फ़िल्टर तय किए जा सकते हैं
    ट्रैक कर सकते हैं जो खास कार्रवाइयों, कैटगरी, और डेटा से मेल खाते हैं. ऐसा करने के लिए, बनाएं
    IntentFilter. इस पहले स्निपेट में फ़िल्टर निर्धारित करने का तरीका बताया गया है:
Kotlin
// Class that displays photos class DisplayActivity : FragmentActivity() { ... override fun onCreate(savedInstanceState: Bundle?) { ... super.onCreate(savedInstanceState) ... // The filter's action is BROADCAST_ACTION var statusIntentFilter = IntentFilter(BROADCAST_ACTION).apply { // Adds a data filter for the HTTP scheme addDataScheme("http") } ...
Java
// Class that displays photos public class DisplayActivity extends FragmentActivity { ... public void onCreate(Bundle stateBundle) { ... super.onCreate(stateBundle); ... // The filter's action is BROADCAST_ACTION IntentFilter statusIntentFilter = new IntentFilter( Constants.BROADCAST_ACTION); // Adds a data filter for the HTTP scheme statusIntentFilter.addDataScheme("http"); ...
    BroadcastReceiver और
    सिस्टम का इस्तेमाल करने पर, IntentFilter का इंस्टेंस पाएं
    LocalBroadcastManager और इसके
    registerReceiver()
    तरीका. इस अगले स्निपेट में, BroadcastReceiver को रजिस्टर करने का तरीका बताया गया है
    और IntentFilter:
Kotlin
// Instantiates a new DownloadStateReceiver val downloadStateReceiver = DownloadStateReceiver() // Registers the DownloadStateReceiver and its intent filters LocalBroadcastManager.getInstance(this) .registerReceiver(downloadStateReceiver, statusIntentFilter) ...
Java
// Instantiates a new DownloadStateReceiver DownloadStateReceiver downloadStateReceiver = new DownloadStateReceiver(); // Registers the DownloadStateReceiver and its intent filters LocalBroadcastManager.getInstance(this).registerReceiver( downloadStateReceiver, statusIntentFilter); ...
    एक BroadcastReceiver पर एक से ज़्यादा तरह के ब्रॉडकास्ट मैनेज किए जा सकते हैं
    Intent ऑब्जेक्ट, हर ऑब्जेक्ट के लिए अपनी कार्रवाई है. इस सुविधा की मदद से, ये काम किए जा सकते हैं
    हर कार्रवाई के लिए अलग-अलग कोड का इस्तेमाल करें. इसके लिए, अलग से
    हर कार्रवाई के लिए BroadcastReceiver. दूसरे को परिभाषित करने के लिए
    इसके लिए IntentFilter
    BroadcastReceiver, IntentFilter बनाएं और
    इस कॉल को दोहराओ
    registerReceiver().
    उदाहरण के लिए:
Kotlin
/* * Instantiates a new action filter. * No data filter is needed. */ statusIntentFilter = IntentFilter(ACTION_ZOOM_IMAGE) // Registers the receiver with the new filter LocalBroadcastManager.getInstance(this) .registerReceiver(downloadStateReceiver, statusIntentFilter)
Java
/* * Instantiates a new action filter. * No data filter is needed. */ statusIntentFilter = new IntentFilter(Constants.ACTION_ZOOM_IMAGE); // Registers the receiver with the new filter LocalBroadcastManager.getInstance(this).registerReceiver( downloadStateReceiver, statusIntentFilter);
    Intent भेजने से, न तो कोई ब्रॉडकास्ट शुरू होता है और न ही उसे फिर से शुरू किया जाता है
    Activity. एकBroadcastReceiver
    Activity, Intent ऑब्जेक्ट को रिसीव और प्रोसेस करता है
    जब आपका ऐप्लिकेशन बैकग्राउंड में चल रहा हो, लेकिन उसे फ़ोरग्राउंड में चलाने के लिए मजबूर न किया जा रहा हो. अगर आपको
    उपयोगकर्ता को बैकग्राउंड में हुए किसी इवेंट के बारे में सूचना देना चाहते हों, जबकि आपका ऐप्लिकेशन
    और Notification का इस्तेमाल करें. शुरू करना कभी नहीं
    आने वाले ब्रॉडकास्ट के मैसेज के जवाब में Activity
    Intent.
