Is it better code practice to register a receiver in manifest or in code?

前端 未结 4 1620
北恋
北恋 2021-01-18 07:19

I\'m writing a simple broadcast receiver. I\'ve registered receivers in both the manifest and in the code before. For my purposes this is a simple receiver that doesn\'t nee

4条回答
  •  攒了一身酷
    2021-01-18 08:11

    Simply put

    Dynamic Registration - Your app expects something to happen immediately while the app is running

    Static Registration - You app is waiting for something to happen over the long term. And since you cannot guarantee your app will be running when it happens you can politely ask the android system to notify you when it does

    They both would have the same execution beyond that point

提交回复
热议问题