wood burning stoves 2.0*
The moose likes Android and the fly likes Not able to write to SDCard while screen is off even though I have PARTIAL_WAKE_LOCK Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Mobile » Android
Bookmark "Not able to write to SDCard while screen is off even though I have PARTIAL_WAKE_LOCK" Watch "Not able to write to SDCard while screen is off even though I have PARTIAL_WAKE_LOCK" New topic
Author

Not able to write to SDCard while screen is off even though I have PARTIAL_WAKE_LOCK

Greg Olson
Greenhorn

Joined: Jan 16, 2011
Posts: 1
I'm totally new to this, so I think I'm probably missing something obvious.
I'm writing an app where I sample the orientation sensor and write the result to a file on the SDCard as well as display it in a log on the screen.
Everything works fine while the screen is on. Since I want to also operate while the screen goes dark, I added code to acquire a PARTIAL_WAKE_LOCK.
From what I can tell, when the screen goes dark the sensors are still being sampled (making me think the wake lock worked), but none of the results are written to the SDCard. I think this is what is happening, because when I reawaken the screen by pressing the menu key, the log on the screen has all the transitions displayed that took place while the screen was off. But, when I look at the file created on the SD card, the only transitions recorded in the file are the ones that occurred while the screen was on.
As for how I'm writing the file I have tried (I think I'm saying this right...) a FileWriter wrapped in BufferedWriter, and a FileWriter wrapped in a FileOutputStream.
At first, the orientation sensor wasn't working even though I had the wake lock until I learned a work around where I added a BroadcastReceiver for Intent.ACTION_SCREEN_OFF and when I get it, I unregister the orientation listener, then re-register it.
Do I need to "unregister" the FileWriter and "re-register" it or something?
The weird part is that the output file contains all orientation changes before the Intent.ACTION_SCREEN_OFF is received, and all of them after Intent.ACTION_SCREEN_ON is recieved when I power the screen back up, but nothing in between.

I'm writing for Android 1.6 (I have a G1)
My project is set to use SDK 4
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Not able to write to SDCard while screen is off even though I have PARTIAL_WAKE_LOCK