localbroadcastmanager


Unable to update UI from IntentService

亡梦爱人 提交于 2019-12-25 08:53:37
问题 A seemingly simple requirement - to update UI from an IntentService . In the shot below, when the Start Service button is clicked, I need to show a ProgressBar above the only TextView and after a delay, remove the ProgressBar . Found a lot of answers on SO, but somehow unable to still crack it. I understand from this that LocalBroadcastManager is a good way to go. I have also tried following this, (an approach with Handler s), but it fails to show the ProgressBar too. Finally, based on this

Does LocalBroadcastManager deliver events in the order in which the events wer sent?

左心房为你撑大大i 提交于 2019-12-24 01:56:16
问题 I have an activity A and a service S. They commute via LocalBroadcastManager. If S calls sendBroadcast twice with two messages M1 and M2 in order, will A get M1 before M2? Thanks, 回答1: LocalBroadcastManager has two ways for you to broadcast; sendBroadcast() and sendBroadcastSync() . One is synchronous, and the other is asynchronous. sendBroadcastSync() blocks until the receiver for the first message is done running. 回答2: Not necessarily. This call deliver method is asynchronous, there is

BroadcatReceiver declared in manifest.xml not receiving LocalBroadcastManager intents

早过忘川 提交于 2019-12-22 04:43:46
问题 While it is possible to declare a 'Local' BroadcastReceiver via code so it receives intents published via a LocalBroadcastManager.Ex LocalBroadcastManager.getInstance(this).registerReceiver(new FooReceiver(), new IntentFilter("foo_intent_filter")); I wonder if it is possible to declare such receiver via the manifest .xml (cleaner) . When I use the 'manifest way', the receiver is not 'receiving' the intents. <receiver android:name="FooReceiver" android:enabled="true" android:exported="false" >

Can i use AlarmManager with LocalBroadcastManager on android?

我是研究僧i 提交于 2019-12-19 05:33:21
问题 I've got this code: private AlarmManager alarmManager = (AlarmManager)getSystemService(Context.ALARM_SERVICE); private PendingIntent alarmIntent = PendingIntent.getBroadcast(this, 0, new Intent("my action-name"), 0); alarmManager.setInexactRepeating((int)AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + autoUpdateIntervalInMinutes * 60 * 1000, autoUpdateIntervalInMinutes * 60 * 1000, alarmIntent); But I would like to change this for LocalBroadcastManager. Is this possible?

Local broadcast from Service not received by Activity

做~自己de王妃 提交于 2019-12-12 09:36:22
问题 I have an Activity in which I am registering a BroadcastReceiver locally as follows: public class SomeActivity extends Activity{ public static final String PERFORM_SOME_ACTION = "PERFORM_SOME_ACTION"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.some_activity_layout); ..... ..... IntentFilter filter = new IntentFilter(); filter.addAction(PERFORM_SOME_ACTION); receiver = new BroadcastReceiver() { @Override public

Avoid registering duplicate broadcast receivers in Android

喜夏-厌秋 提交于 2019-12-11 03:08:49
问题 I am trying to create my first Android app. I would like a main-thread Activity (in my case: an ActionBarActivity) to receive notification of an event from a background Activity (in my case: an IntentService). I've read that using broadcasts should be the best way to do this. To register a Broadcast Receiver for listening to broadcasts sent from the background activity, I am using the following code inside the main-thread activity: // Register broadcast receiver LocalBroadcastManager bManager

Locally managed broadcast receiver leak?

 ̄綄美尐妖づ 提交于 2019-12-10 16:16:44
问题 Is it possible that a local (i.e. managed with LocalBroadcastManager) BroadcastReceiver leaks when the app is killed by the system? The specific use case for which I need it is that I would like to register/unregister the BroadcastReceiver in an Activity's onCreate/onDestroy (I need the receiver to be active when the activity is not visible), but I wouldn't like to risk causing a memory leak by doing this. As I understand, if a single activity is destroyed by the system, onDestroy runs and

IntentService LocalBroadcastManager not reaching Receiver

夙愿已清 提交于 2019-12-08 08:49:17
问题 I'm using Android Studio 1.3, I have an IntentService setup that gathers some data and sends it out via a LocalBroadcastManager as so: IntentService public class cService extends IntentService { public cService(){ super("cService"); } @Override protected void onHandleIntent(Intent intent) { SoapPrimitive response = (SoapPrimitive)envelope.getResponse(); Intent broadcastIntent = new Intent("action.getTestData"); broadcastIntent.putExtra("data", response.toString()); LocalBroadcastManager

Cannot receive broadcast in Activity from LocalBroadcastManager in IntentService

强颜欢笑 提交于 2019-12-08 03:24:05
问题 it is very simple code to use broadcast between Activity and IntentService. The MainActivity starts SyncService (which is an IntentService), the SyncService broadcasts messages and MainActivity should receive the messages from SyncService (by using BroadcastReceiver). but it is strange that the MainActivity cannot get any message from SyncService. Somehow if I call LocalBroadcastManager to broadcast message directly in MainActivity (onCreate() method), the receiver can get the message. is it

Cannot receive broadcast in Activity from LocalBroadcastManager in IntentService

亡梦爱人 提交于 2019-12-06 15:37:00
it is very simple code to use broadcast between Activity and IntentService. The MainActivity starts SyncService (which is an IntentService), the SyncService broadcasts messages and MainActivity should receive the messages from SyncService (by using BroadcastReceiver). but it is strange that the MainActivity cannot get any message from SyncService. Somehow if I call LocalBroadcastManager to broadcast message directly in MainActivity (onCreate() method), the receiver can get the message. is it because of the different context to initialize LocalBroadcastManager? or there is any other problem?

工具导航Map