Вопрос

I was wondering if Android's BroadcastReceiver's onReceive() message can result in race conditions and/or deadlocks? I have read Android's developer pages in regards to the BroadcastReceiver's onReceive() method but cannot discern the answer to my question. Let's assume that I have implemented code that writes a number to a .txt file each time I receive a new text message. If I receive two text messages at exactly the same time do I need to worry about the file being updated at the same time?

Thanks in advance for your help, suggestions, and answers.

Это было полезно?

Решение

No, there is no need to worry.

The onReceive method is called from the main thread of your application. Therefore, only one can be executed at a time. (This also mean that you must never block that thread, and try to return as quickly as possible)

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top