File Storage in Android

Files locations – There are several important locations where you can read or write files.

  • File.DirAssets

The assets folder includes the files that were added with the file manager. These files are read-only. You can not create new files in this folder (which is actually located inside the apk file).

  • File.DirInternal / File.DirInternalCache

These two folders are stored in the main memory and are private to your application. Other applications cannot access these files. The cache folder may get deleted by the OS if it needs more space.

  • File.DirRootExternal

The storage card root folder.

    • File.DirRootExternal = “/mnt/sdcard”
  • File.DirDefaultExternal

The default folder for your application in the SD card. The folder is: <storage card>/Android/data/<package>/files/ It will be created if required.


Start new application

To start new application in B4A

  • Launch B4A, the system will start with new code template
  • First save it with the project is the first step otherwise you will not able to use Designer
    • Save the project you need to name the packgage name which will diffientiate your application from the other application which may have the same name. For example “” (all in lower case) and you need to give the label name which is you application name.
    • Then launch your emulator, recomend to create many sceen size in order to test your application before release start from the smallest to big table. Then use the HVGA (320×480) Medium Density 160 dpi as the start variance.
  • Think of user interface and launch the designer
  • Then connect your designer with the emulator
  • Populate the user interface in Virtual Desiner and see how it look like in emulator.
    • The Page or windows form is called “Activity”
    • The user interface object such as button, label etc are called “View”
    • Name your view with leading btn, lbl, edt such as btnAction, lblUserAge, edtYourName
    • Given the tag which will be use in Select case in the event drive sub routine that handle use input
    • Many view may share the same event sub routine
  • Save the Layout you create in the designer and give it a name the first one is “Main”
  • Then Generate Member, select the view that you will use in the programe (Not all the view you may need to DIM it) and select the event of each view that you want to response, The desinger will generate the DIM statement in “Globals Sub” code section and create Event Sub for you.
  • Add the default code
    • Add “Activity.LoadLayout(“Main”) in “Activity_Create Sub”, I think that it should include in the template
  • Start your programming job
    • Define public variable in “Globals Sub” or “Process_Globals Sub”
    • Initialization in “Activity_Create Sub” use If FirstTime for first time initilazation only
    • Code your response to all event sub
    • And Sub as need
  • Select debug and run program add break point add Log(“text message”) as needed
  • After you Application is bug free then think about support multiple screen size by add Designer Scripts or Layout Variants and code to check screen size
  • Test againt different screen size
  • Release your program by change mode from Debug to release then run program again
  • You can find your apk program in Object Directory of your project

Emulator and Windows Keys

  • Emulator
  • Power button = F7
  • Home = HOME
  • Back = ESC
  • Menu (left softkey) = F2 or Page-up button
  • Audio volume up button = KEYPAD_PLUS, Ctrl-F5
  • Audio volume down button = KEYPAD_MINUS, Ctrl-F6
  • Switch to previous layout orientation (for example, portrait, landscape) = KEYPAD_7, Ctrl-F11
  • Search = F5
  • Switch to next layout orientation (for example, portrait, landscape) = KEYPAD_9, Ctrl-F12

  • Toggle cell networking on/off = F8
  • Star (right softkey) = Shift-F2 or Page Down
  • Call/dial button =F3
  • Hangup/end call button = F4
  • Camera button = Ctrl-KEYPAD_5, Ctrl-F3
  • Toggle code profiling = F9 (only with -trace startup option)
  • Toggle fullscreen mode =Alt-Enter
  • Toggle trackball mode = F6
  • Enter trackball mode temporarily (while key is pressed) = Delete
  • DPad left/up/right/down = KEYPAD_4/8/6/2
  • DPad center click = KEYPAD_5
  • Onion alpha increase/decrease = KEYPAD_MULTIPLY(*) / KEYPAD_DIVIDE(/)

Screen Resolution

User Interface

ListView VS ScrollView

Leave a Reply