0

I encounter a strange thing about the android sdcard in my HTC Desire S, I have one application which has the some actions to sdcard in the onCreate function, and this application will be start when phone boot.

Now I installed this application, and restart the Phone, when the phone restarted, my application crashed, i find it caused by the sdcard is null. I have no idea about it. Is my fault? or the android not prepared the sdcard before the application stared?

regrecall
  • 521
  • 1
  • 6
  • 20

1 Answers1

0

You have to wait that the sdcard is mounted with ACTION_MEDIA_MOUNTED in your intent.

When the phone starts, it can take some times before the sdcard is ready (filesystem checks, errors recovering etc.)

noli
  • 3,535
  • 3
  • 18
  • 20
  • why the android system start application after the sdcard is ready? – regrecall Apr 17 '12 at 08:29
  • `Common.HOME_DIRECTORY = ctx.getExternalFilesDir(null).getAbsolutePath() + Common.ADVERTISE_DIRECTORY;` In my application onCreate, and i found the ctx.getExternalFilesDir(null) is null. – regrecall Apr 17 '12 at 08:35
  • I suggest you to add a BroadcastReceiver in your app, look at http://stackoverflow.com/questions/3417161/android-intent-for-sdcard-ready. Implement this before any interaction with the sdcard (above the 'getExternalFilesDir()') – noli Apr 17 '12 at 08:42