Reputation: 32233
Is possible to launch broadcast with application scope? That is: broadcasts undetectable out of the application?
I was using broadcast for communicate some events to the UI. But recently I recycled some of my code for another app and I found that the broadcasts were awakening both applications (as it was expected). So I wonder if there is any way around this besides changing the value of "action" of Intent
Upvotes: 4
Views: 4823
Reputation: 8034
You should use LocalBroadcastManager, its best alternative to normal broadcast, if you want intra application message passing. Read this post for implementation: how to use LocalBroadcastManager?.
Upvotes: 5
Reputation: 55585
Use LocalBroadcastManager. You will need to include the support library, but this is a great solution for solving this issue as it is more efficient than sending a global broadcast through the system.
Upvotes: 1
Reputation: 12610
@Lukap: Signed applications is an essential feature in all Android versions to allow only authorized parties to provide updates/changes for an installed app.
All applications must be signed. The system will not install an application on an emulator or a device if it is not signed.
Plus:
Note: using broadcast for inter communication in the app is wrong
This is wrong. There are a number of reasons to use broadcast inside an application, and some situations where you really cannot live without it.
Upvotes: 1
Reputation: 31963
I think you will have to change your action, If you use setComponent that's explicit intent, then if that is fine for you it will work, but for implicit intent you can not restrict by application
There is cyanogenmod where you can sign your application and you can prevent instaling apps in you phone with different signature, which means ones you install something on phone no one will be able to install new app(except you) and this can restasure that no one will register receiver with the same action name as you
Note: using broadcast for inter communication in the app is wrong and slower than normal call to procedure (which is possible in your case). I do not see a reason why you shouldn't make a normal call.
Upvotes: 1
Reputation: 7964
Why do not you use observer-observable pattern to communicate among java classes in your application ?
Upvotes: 2
Reputation: 38707
Yes, you can use the component name via Intent.setComponent()
.
But if your broadcast is always going to be in-process, there's no need to use it, is there? You can just use a plain old function call...
Upvotes: 1