Android Question Anyone remembers .INI files in windows before registry ?

Said

Member
Licensed User
Longtime User
I am planning to make little ini file and put some variables there (file) and get and use sometimes. Mostly saving for defaults.

Any easy method for this ? Any tutorial around ?

-regards
 

Mark Read

Well-Known Member
Licensed User
Longtime User
The first thing that springs to mind is using a map.
 
Upvote 0

Said

Member
Licensed User
Longtime User
Thanks. I was looking for forum and i think, map is method which i am looking for.

But i didnt see any tutorials about it. Only some example parts. Any tutorial around about maps ?
 
Upvote 0

Said

Member
Licensed User
Longtime User
Erel,

Your example is ok but i want to different thing. Little explanation;

Actually i want to set control's default values but have a special situation. Its little game settings but user have two choice to setup game variables.

1. Last game settings
2. His defaults, which he built before

For this, i have to build two different set of variables for screen control defaults. Looks like i can do what i want, with maps but i didnt found any simple and complete example/tutorial. Is there any simple tutorial for maps around ?

Ps: Btw, statemanager looks cool and i'll use it in other projects. But have a question about it. Does it capability to save file, or only "memory refresh" ?
 
Last edited:
Upvote 0

Said

Member
Licensed User
Longtime User
Because of i want to two different settings for control, its not helping me at this moment but its good to hear, statemanager saving settings to "disk" for after restarting device use. My searching about map still continues. Thanks for information sorex...
 
Upvote 0

canalrun

Well-Known Member
Licensed User
Longtime User
Hello,
I use Maps in the same way that I used to use INI files.

I declare my maps in globals:
Public MyMap as Map

in Activity Create (when FirstTime is True) I initialize the map and check to see whether the map file exists otherwise I load the map default values:
If (FirstTime) Then MyMap.Initialize

If (File.Exists(File.DirDefExternal, "MMFile.txt") = False) Then
MyMap.Put("somevar", 0)
File.WriteMap(File.DirDefExternal, "MMFile.txt", MyMap)
End If
End If

In Activity Resume I read the map file
MyMap = File.ReadMap(File.DirDefExternal, "MMFile.txt")

In Activity Pause I write the map file
File.WriteMap(File.DirDefExternal, "MMFile.txt", MyMap)

Within the program code I can use the values in the map file directly almost as if they were variables
i = MyMap.Get("somevar")

Note: This was all written off the top of my head so there may be some small syntax and spelling errors – I can't guarantee it will compile correctly, but it does show how I use the Map as an INI.

Also Note: It may be worth considering using DirInternal instead of DirDefExternal. The external directory may not exist on some devices, but it's not a protected directory that's hidden from view.

Barry.
 
Upvote 0

Said

Member
Licensed User
Longtime User
Thanks Barry.

Your code working perfect. I adapted to my project and now i am ok.

In this project, i'll use both map and StateManager. Map for user built default parameters, StateManager for deactivation, reactivation process.

I used DirInternal for maps. Is there any way to see and check that file (defaults.set) from PC ? I am using emulator.

-Regards
 
Upvote 0

canalrun

Well-Known Member
Licensed User
Longtime User
As far as I know (someone correct me if I'm wrong), DirInternal is a protected directory and can be accessed only by the app that creates it or by someone with a Rooted device. This means that file managers and FTP programs also can't access the directory.

DirDefExternal resides on the SDCard and is globally accessible. File managers and FTP programs can access this directory.

My guess is that ADB follows the same conventions, although I've never tried.

There is a function, something like, File.ExternalWritable that tests if the DirDefExternal exists and is writable. I sometimes create a new variable:
If (File ExternalWritable) Then AppDir = File.DirDefExternal else AppDir = File.DirInternal

then I use AppDir as the location of all my maps.

Barry.
 
Upvote 0

Said

Member
Licensed User
Longtime User
Okay.

Then only two way to control my defaults.set, which resides dirinternal.

I can copy it with code or i can add view to see it. Its just curiosity. It gives results what i want. Bu i wonder structure of this ini file.

-regards.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…