To answer my own question, I think I'm looking for code like that below.
public void waitForExternalStorage()
{
while(Environment.getExternalStorageState().equals(Environment.MEDIA_CHECKING))
{
try { Thread.sleep(1000L); }
catch(InterruptedException e) { e.printStackTrace(); }
}
}
Alternately, I can wait for a broadcast of Intent.ACTION_MEDIA_MOUNTED.
Have I got the right? And is there anything else I should be wary of in
this start-at-boot scenario?
On Friday, October 19, 2012 1:13:43 PM UTC-4, Bill Michaelson wrote:
>
> I recently modified an application such that a component Service is now
> started upon device boot via RECEIVE_BOOT_COMPLETED. But when the service
> started, I encountered a problem with sqlite opening - a failure that was
> critical to the application. Upon examining adb logcat output, I noticed
> messages that announced phases of fsck operating, and implying that fsck
> did not complete until after my sqlite open failure. I assumed that the
> underlying file was inaccessible because my app started too early relative
> to fsck. Based on this hunch, I inserted a 5 second Thread.sleep() into
> the start sequence. This seems to have solved the problem.
>
> But I am unsatisfied for two reasons:
>
> 1) My fix is non-deterministic. There is no guarantee that 5 seconds will
> always be adequate, or theoretically, that any arbitrary delay is
> sufficient.
> 2) I have not absolutely determined a causal relationship between the fsck
> and the open failure.
>
> Ideally, I will delay start until precisely the moment that the OS and
> supporting processes are adequately prepared.
>
> So I seek advice from a more imaginative, knowledgeable or experienced
> developer.
>
> TIA
>
>
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en