localbroadcastmanager

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?

How to use LocalBroadcastManager without Activity

拜拜、爱过 提交于 2019-12-05 02:48:53
问题 I had my class ' ABC ' by extending the BroadcastReceiver . But recently, I stumbled upon LocalBroadcastManager . here is my class declaration: public class ABC extends BroadcastReceiver {} So ABC is working as the listener and based on the action it would call another object. I checked everywhere whether I can use LocalBroadcastManager here without an activity. Actually class ABC is a core application class where it doesn't connect to any UI component. Let me know how can I use

Local broadcast from Service not received by Activity

僤鯓⒐⒋嵵緔 提交于 2019-12-05 02:39:11
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 void onReceive(Context context, Intent intent) { // perform some action ... } }; registerReceiver(receiver

Can i use AlarmManager with LocalBroadcastManager on android?

北城以北 提交于 2019-12-01 03:07:32
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? No, it is not possible, because LocalBroadcastManager is only for your own process, and AlarmManager

Register a Local BroadcastReceiver in AndroidManifest.xml?

混江龙づ霸主 提交于 2019-11-30 16:54:23
Is there anyway to register a BroadcastReceiver in AndroidManifest.xml and receives broadcast that is send by a LocalBroadcastManager? Currently I must call registerReceiver(BroadcastReceiver receiver, IntentFilter filter) to register a Receiver, declare in AndroidManifest.xml won't work. But this means I must know exactly the receiver's package name and class name, not just the intent filter. Is it possible to declare the receiver in the manifest file? following is my current code. AndroidManifest.xml: ... <receiver android:name="com.example.test.MessageReceiver" android:enabled="true" >