Call activity method from broadcast receiver android?

后端 未结 5 1825
猫巷女王i
猫巷女王i 2021-01-07 15:19

In my application I am sending a port SMS to the mobile. And when the message is recieved I need to perform some task in my activity and update the UI.

Manifest Decl

5条回答
  •  灰色年华
    2021-01-07 16:10

    that ((VerifyActivity)context).msgReceived(msg); that's your mistake. Why are you assuming that this context is your activity?

    The best way (without 3rd party libraries) to do this is to send a local broadcast.

    On this other answer I gave a general idea on how to use LocalBroadcast Best practice to launch AsyncTask from custom view

    if you're Ok using 3rd party libraries I suggest you check Otto from Square

提交回复
热议问题