1

In my app I am receiving data at onReceive() of various Broadcast receivers. I need to write the intent data I receive into a single file. Every time I receive an intent at any of 4 broadcast receivers I open the same file to write and close it. Sometime many onReceive() are invoked and I need to.

I want to know what is the best mechanism for writing to file. I explored on synchronization, use of Queue etc. But these were good mechanism for writing from multiple threads.

So my Question is each onReceive() equivalent to a thread here?

If yes which mechanism is best to write to a single file on SD card.

If no, Just a regular write is fine(without any locking/synchronization etc)

newfurniturey
  • 37,556
  • 9
  • 94
  • 102
harshkn
  • 731
  • 6
  • 13
  • http://stackoverflow.com/questions/5674518/does-broadcastreceiver-onreceive-always-run-in-the-ui-thread So, unless you use a handler, it should be fine. – Submersed Dec 17 '13 at 15:10
  • 1
    So,You mean since onReceive() runs on UI thread, there is no chance of different onRecieve() method open the file simultaneously for write? Thanks. – harshkn Dec 17 '13 at 15:17
  • 1
    Correct, onReceive() runs on the UI thread. So you do not need to worry about something else trying to access the same file concurrently, as long as you don't have code elsewhere that would cause such a conflict. – Eric Schlenz Dec 18 '13 at 17:21

0 Answers0