0

We are having trouble with local broadcasts. For some reason in 2 androids(my own phone + boss's phone) it works fine. On another phone(galaxy s3 mini like my boss) and on boss's tablet it however crash. Program crash if the tmp.sendBroadcast command is but not right away(it still does bit after that). However it never gets to receiver.

public class UpdaterIntent extends IntentService {

...

Intent intent = new Intent("my-event");
            intent.putExtra("action", "update_workplaces");
            intent.putExtra("parameters", time);


LocalBroadcastManager'tmp=LocalBroadcastManager.getInstance(myInst);


            if(tmp!=null) {
                tmp.sendBroadcast(intent);

            }

I have registered receiver like this:

LocalBroadcastManager.getInstance(this).registerReceiver(mMessageReceiver,
                new IntentFilter("my-event"));

Receiver is this:

private BroadcastReceiver mMessageReceiver = new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {
        Toast.makeText(myContext, "received message", Toast.LENGTH_SHORT).show();

        }

    }
};

I have tried to search for some reason why it might be so. Thought it might have been too long parameters as putExtra but even after trimming it to two strings(one seen in code, one is just a date that comes from server like "2014-03-28 12:20:02" etc so now there shouldn't be danger of exceeding some hard coded limit.

Any suggestions? Don't like any workarounds to this that I have come up with being clumsy as hell.

user1396135
  • 11
  • 1
  • 3
  • 2
    do you have any chance to post logcat? – nikis Mar 28 '14 at 08:36
  • Is there any reason debug mode in mode would be undesirable if you aren't using it for debugging normally? Would have to sell idea of switching that mode for their personal devices. The crash doesn't happen on either of devices that are meant for developing(particularly my phone. Would be lot easier if it would happen with it). Maybe next week I can get my hands on the phones. Unless there's way they could upload it via email by using phone itself(I doubt they are going to be willing to go trouble of learning how to use the adb console) – user1396135 Mar 28 '14 at 08:46

1 Answers1

0
LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
P.J
  • 6,547
  • 9
  • 44
  • 74
hepizoj
  • 243
  • 4
  • 9
  • Please add a little explanations. Code only answers are considered low quality on stackexchange. – Lorenz Meyer Mar 28 '14 at 10:54
  • Ok I'll try this one though the myInst is prestored variable that has "this" as value. Not sure why it would fix it(also this as such won't work. Forgot to mention the localbroadcastmanager is called within AsyncTask so this isn't valid within that. Might it being called within AsyncTask be causing the crash? – user1396135 Mar 31 '14 at 05:06