Android BroadcastReceiver within Activity

后端 未结 7 1474
后悔当初
后悔当初 2020-11-28 23:59

I\'m just trying this little sample project, all it does: Activity one has a Button that sends a Broadcast. Activity two displays a toast when received. Below is the code, t

7条回答
  •  旧时难觅i
    2020-11-29 00:06

    I think your problem is that you send the broadcast before the other activity start ! so the other activity will not receive anything .

    1. The best practice to test your code is to sendbroadcast from thread or from a service so the activity is opened and its registered the receiver and the background process sends a message.
    2. start the ToastDisplay activity from the sender activity ( I didn't test that but it may work probably )

提交回复
热议问题