send broadcast from Service to Activity?

前端 未结 2 1232
迷失自我
迷失自我 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..

提交回复
热议问题