Saving variable to file, and use it for tcp/ip connexion.

ciprian

Active Member
Licensed User
Longtime User
Hi there. I need some help in my project and i hope you can give me a hand.
In my project, i connect to an relayboard in tcp/ip, and send commands to on/off the relays.
All works fine until here...
The problem is that i want to ask the user of my app to write the ip adress and the tcp/ip port and then store them to a file, to use it later for connecting socket.
How can i do that please?
 

warwound

Expert
Licensed User
Longtime User
Or AHPreferenceActivity.

Using AHPreferenceActivity you'll have a ready built UI to allow the user to enter the IP address etc and be able to add more settings/preferences if required.

Martin.
 
Upvote 0

ciprian

Active Member
Licensed User
Longtime User
Thankyou. I'm a newbie so it's giving me some headakes....i'll try both....even if AHPreferenceActivity sounds good for me....
Hope i will be able to understand by my self.
 
Upvote 0

ciprian

Active Member
Licensed User
Longtime User
Okay, it's been 2 months since i discovered basic4android, i'm not a developer, just an automatics technician. I'm learning a lot, even if i don't have enough time to study...i'm loving it. Thankyou all for helping, kindness and all great ideas and tutorials i can find in here.
 
Upvote 0

ciprian

Active Member
Licensed User
Longtime User
In AHPreferenceActivity example, i chosed two edit-text for my ip adress and the port (TCP/IP) . How can i use the stored text as a string for my TCP stream connection?
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
You'll have an instance of the AHPreferenceManager and you need to use it's GetString(Key As String) method.

To create the IP address and port EditTexts you must have used the method:
AddEditText (Key As String, Title As String, Summary As String, DefaultValue As String, Dependency As String)

So your IP address and port EditTexts allow the user to enter values and each value has a unique key, the key is the key used in AddEditText.

Pass this key to GetString(Key As String) and you'll get your stored value.

The official PreferenceActivity tutorial can be found here: http://www.b4x.com/android/forum/threads/preferenceactivity-tutorial.10608/, it applies to the official PreferenceActivity as well as the (modified) AHPreferenceActivity.

Martin.
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
They are available in all modules - but you'll need an instance of the AHPreferenceManager to get the values.

The tutorial shows how to have an instance of the AHPreferenceManager as a Process_Global in one module.
Now you can access that instance from the module it was declared in and also from any other module.

To access that instance from a module which it was not declared in you prefix the instance name with the name of the module it was delcared in:

B4X:
Main.MyPreferenceManager.GetString("port")

Here i'm assuming that in module Main you have declared MyPreferenceManager as a Process_Global.
From module main you'd use:

B4X:
MyPreferenceManager.GetString("port")

From all other modules you'd use:

B4X:
Main.MyPreferenceManager.GetString("port")

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