SendOrderedBroadcast Help

Put your problem here if it does not fit any of the other categories.

SendOrderedBroadcast Help

Postby Draffodx » Mon May 31, 2010 3:34 pm

I am trying to use a sendOrderedBroadcast in my Android app.

I want to be able to send the Intent from one of my applications to another and I then want to get data back from the Application that recieves the Intent, in this case a boolean true or false.

Here is the current code:

Code: Select all
    Intent i = new Intent();
    i.setAction(GlobalData.PROPOSE_IN_DOMAIN_ROAM_INTENT);
    i.putExtra("com.testnetworks.QCLEVEL", aProposedTheoreticalQoSLevel);
    sendOrderedBroadcast(i, null, null, null, Activity.RESULT_OK, null, null);


Is this the correct way to achieve what I want?

If so what do I use as the resultReceiver* parameter? (3rd parameter)

And then how to I recieve data back from the Broadcast?

I have done a quick google and not come up with any examples, any help or examples greatly appreciated.

*resultReceiver - Your own BroadcastReceiver to treat as the final receiver of the broadcast.
Draffodx
Master Developer
Master Developer
 
Posts: 205
Joined: Wed Nov 12, 2008 2:31 pm

Top

Re: SendOrderedBroadcast Help

Postby Draffodx » Tue Jun 01, 2010 9:24 am

Answer Thanks to Tim Kryger on Stack Overflow

1


You need to get the extra data results Bundle and add your data to it.

Try something like this:

Code: Select all
public class DemoOrderedBroadcast extends Activity {
    private static String SOMETHING_HAPPENED = "com.example.somethinghappened";
    private static String EXTRA_INTEGER = "extra integer";

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        IntentFilter filter = new IntentFilter(SOMETHING_HAPPENED);

        registerReceiver(new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                Bundle results = getResultExtras(true);
                results.putInt(EXTRA_INTEGER, 100);
                Log.d("DemoOrderedBroadcast",
                        "In Initial Receiver: Put 'extra integer' = 100");
            }
        }, filter);

        Intent intent = new Intent(SOMETHING_HAPPENED);
        sendOrderedBroadcast(intent, null, new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                Bundle results = getResultExtras(true);
                Log.d("DemoOrderedBroadcast",
                        "In Result Receiver: Got 'extra integer' = "
                                + results.getInt(EXTRA_INTEGER, -1));
            }
        }, null, Activity.RESULT_OK, null, null);
    }
}
Draffodx
Master Developer
Master Developer
 
Posts: 205
Joined: Wed Nov 12, 2008 2:31 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Google [Bot], MSNbot Media and 13 guests