In your code, you're calling registerReceiver() from your onClick(),
meaning that from then on, your receiver will respond to broadcasts of
the intent in question. You're never actually broadcasting that intent
though.
You probably want to call registerReceiver() from your onCreate(), and
then send the broadcast in onClick(). You might also want to think
about using a Handler instead.




On Mon, Feb 23, 2009 at 7:55 AM, Birds <[email protected]> wrote:
>
>
> hi all,
>  This is my code.
>
> public class MyThreadActivity extends Activity {
>        /** Called when the activity is first created. */
>        @Override
>        public void onCreate(Bundle savedInstanceState) {
>                super.onCreate(savedInstanceState);
>                setContentView(R.layout.main);
>
>                Button b = (Button) findViewById(R.id.btn1);
>                b.setOnClickListener(new OnClickListener() {
>                        @Override
>                        public void onClick(View arg0) {
>                                Log.d("MyThreadActivity", "MyThreadActivity");
>                                IntentFilter intentFilter = new IntentFilter();
>                                intentFilter.addAction("show.me");
>                                registerReceiver(receiver, intentFilter);
>                        }
>                });
>        }
>
>        /**
>         *
>         */
>        private BroadcastReceiver receiver = new BroadcastReceiver() {
>                @Override
>                public void onReceive(Context context, Intent intent) {
>                        Dialog dialog = new Dialog(MyThreadActivity.this);
>                        dialog.setTitle("showme");
>                        dialog.show();
>                }
>        };
> }
>
> ////  Why the BroadcastReceiver can not start when I click button ?
>     How to start the BroadcastReceiver ?  the registerReceiver method
> was not work .
>
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to