Skip to content

Snappy1

  • Home
  • Android
  • What
  • How
  • Is
  • Can
  • Does
  • Do
  • Why
  • Are
  • Who
  • Toggle search form

[FIXED] android – Why Unregister Broadcast Receiver when I want to receive broadcast even when app is closed?

Posted on November 11, 2022 By

Solution 1 :

If I unregister a receiver once my app is closed, I won’t be able to receive intents to that BroadcastReceiver right?

Yes, if you unregister a receiver via unregisteReceiver() that you registered via registerReceiver(), that receiver will no longer receive broadcasts.

If so wouldn’t that defeat the purpose?

Not really.

You seem to be worried about when your app is “closed”. The verb “closed” is not very specific in this context, but once your app’s UI moves to the background, your process can be terminated at any point in time. When your process is terminated, any receivers that you register with registerReceiver() vanish, along with everything else in the process. Registering a receiver dynamically is only useful while your process is running. So, whether you call unregisterReceiver() or not, when your app is “closed”, you will soon be unable to receive broadcasts.

The primary alternative to registerReceiver() is to register a <receiver> in the manifest. On modern versions of Android, though, manifest-registered receivers cannot receive many broadcasts.

Problem :

this might sound silly but. If I unregister a receiver once my app is closed, I won’t be able to receive intents to that BroadcastReceiver right?? If so wouldn’t that defeat the purpose?

Comments

Comment posted by Samuel Owino

Thanks, @CommonWare this helps a lot, I will consider registering the receiver in a service, hope that will ensure it lives beyond the lifetime of my application

READ  [FIXED] java - How to resolve compiler warning
Powered by Inline Related Posts
Android Tags:android, android-studio, background, broadcastreceiver

Post navigation

Previous Post: [FIXED] android – Convert BMP image to PNG or JPG in Java without loading the entire image in memory
Next Post: [FIXED] xml – Android – prevent TextView to push out another element inside LinearLayout

Related Posts

[FIXED] android studio – How to use a local variable value out it function in flutter? Android
[FIXED] android – RecyclerView.Adapter’s onBindViewHolder() is not called for last position Android
[FIXED] java – Foregound Service start action from MainActivity Android
[FIXED] android – How to implement time picker spinner in flutter? Android
[FIXED] java – Retrieve a file from storage starting with a String Android
[FIXED] android – Can anybody tell me what is wrong with that line of code Android

Archives

  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuándo
  • ¿Cuántas
  • ¿Cuánto
  • ¿Qué
  • Android
  • Are
  • At
  • C'est
  • Can
  • Comment
  • Did
  • Do
  • Does
  • Est-ce
  • Est-il
  • For
  • Has
  • Hat
  • How
  • In
  • Is
  • Ist
  • Kann
  • Où
  • Pourquoi
  • Quand
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welchen
  • Welcher
  • Welches
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Who's
  • Why
  • Wie
  • Will
  • Wird
  • Wo
  • Woher
  • you can create a selvedge edge: You can make the edges of garter stitch more smooth by slipping the first stitch of every row.2022-02-04
  • you really only need to know two patterns: garter stitch

Recent Posts

  • What color are dead flea eggs?
  • What is Indiana vine?
  • What’s the downside of a Chromebook?
  • Is phosphide the same as phosphorus?
  • Why do you need an S bend?

Recent Comments

No comments to show.

Copyright © 2023 Snappy1.

Powered by PressBook Grid Dark theme