send broadcast from Service to Activity?

前端 未结 2 1214
迷失自我
迷失自我 2021-01-07 23:55

I\'m having a problem with sending a broadcast from a Service to an activity.

This is what I have in my Service class:

Intent intent = new Intent();
         


        
相关标签:
2条回答
  • 2021-01-08 00:23

    Like others said, you need to register the activity first to receive those broadcasts (see Flo's answer)

    For your other quesition (re: EDIT). If you are taking the same action, you should create an overall Activity, and have your other activities extend that activity..

    Then in this super class, implement the broadcast receiver registers on onResume and un register onStop..

    0 讨论(0)
  • 2021-01-08 00:35

    You have to register the broadcast receiver before it can receive anything.

    Have a look at this question.

    0 讨论(0)
提交回复
热议问题