How exactly to save data in App Data Storage of applicationcraft? - android

I am newbie to Mobile development, I am using http://motech.applicationcraft.com/ to get some app going. I read about App Data Storage and wanted to use it to save some data.
I have done something like below.
3 text box with storage in d/b value TRUE.
Now I want on Click of Save button this 3 details gets saved.
My guess I need to write some Javascript on click of Save button, not sure how/what?

Pritesh
Internal storage in AC is deprecated so using d/b value= true will not do anything.
Store data securely into your own external database using Server Side functions (see this link )

Use SharedPreference to store data in App.
Like..
public static final String PREFS_NAME = "MyPrefsFile";
SharedPreferences settings = getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = settings.edit();
editor.putString("name" valueOfName);
editor.putString("name" valueOfUserId);
editor.putString("name" valueOfPassword);
editor.commit();

Related

Android save EditText text

I have a school planer app and I want to save the classes that are written in an EditText object. The problem is, the EditTexts are empty when I close the app and then open it again, and even when I press back. This may be a noob question, but I'm a beginner and I need help. Please answer quickly...
for saving edittext text you need to store the text into storage.
android support storage like
Database
Shared Preferences
For your problem you need to store your Edittext text into the storage when you change value.
And when you open it again you need to retrieve from the storage.
For you best option will be shared preferences. For more Go with This Example . This will make you understand save and retrieve shared preferences.
Short Example
Store Data
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
editor = pref.edit();
editor.putString("first_edittext", "value");
editor.commit();
Retrieve Data
SharedPreferences pref = PreferenceManager
.getDefaultSharedPreferences(getBaseContext());
pref.getString("first_edittext", "");

Best way to store a single user in an Android app?

I'd like my app to allow a single user to create a profile that is accessed every time they run the app. The user's profile contains a String entry and five int entries. I've thought about using an SQLite database to store the info between sessions, but it seems like overkill since I'd only need one row in a single table to store the data. However, I'm not sure if it's possible to use SharedPreferences on a String type of data.
Can anyone provide some insight into this issue please? Thank you!
Yes you can use SharedPreferences.
To write
Editor editor = getSharedPreferences("file_name", MODE_PRIVATE).edit();
editor.clear();
editor.putString("pref_name", myStringValue);
editor.commit();
To read back
SharedPreferences preferences = getSharedPreferences("file_name", MODE_PRIVATE);
String myStringValue = preferences.getString("pref_name", "default_value");
Regards.

Write File without MODE_WORLD_READ/WRITE

Okay, I have come across many tutorials on creating and writing/reading a file. What I want my Android app is to create a small text file where it will read and write some settings so my user information can be saved. The problem is every tutorial I have come across uses the SDcard (which allows the user and any other app to read) or use MODE_WORLD_READABLE which makes any app read off of it.
I was wondering how I can create and read/write my file but private or atleast keep it on the internal storage of the phone.
Here's an easy example. To read a preference do this:
SharedPreferences preferences = getSharedPreferences("YourAppName", MODE_PRIVATE);
String thisString = preferences.getString("KeyForThisString", "default");
You can getInt, getLong, etc.
To store the preferences, use these lines:
SharedPreferences preferences = getSharedPreferences("YourAppName",MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.putString("KeyForThisString", thisString);
editor.commit();
As before, you can putInt, putLong, etc.
The available methods for this API are here: http://developer.android.com/reference/android/content/SharedPreferences.html
dont know how to use it much and from what im seeing at least, its not much of a difference unless im wrong.
I still recommend to use SharedPreferences technique. It's explicitly easy and save a lot of time.
You can use it to save any primitive data: booleans, floats, ints, longs, and strings.
For example, you can do that each time when user invokes any changes to your Application because it's high performance technique. By this way even on crash all edited info will be stored.
Suppose you have an Activity.
Use this method where data is your String that you wanted to save to file.
private void saveInfo(String data){
String key = "myKey";
SharedPreferences.Editor editor = mPrefs.edit();
editor.putString(key , data);
editor.commit();
}
Now, when you launch your application again onCreate method invoked and you can load your information back:
private void loadInfo(){
String key = "myKey";
SharedPreferences mPrefs = context.getSharedPreferences(LauncherUI.PREFS_NAME, 0);
String yourData = mPrefs.getString(key, ""); // "" means if no data found, replace it with empty string
}
Here is a link to 5 types to store data: Storage Options

Saving a value on android

I want to save a String value on Android and have access to this
String every time the application starts.
For instance the String value will have the user's name which he has created by
his own. And after restaring the api he would have this name already on the top.
Like a cookie or sth. How to save such file on android memory ?
Can someone guide me?
Use the following:
private static final String PREFS_NAME = "YOUR_TAG";
private static final String DATA_TAG = "DATA_TAG";
private static final String data = "oh, what a data!";
//init
SharedPreferences mSettings = context.getSharedPreferences(PREFS_NAME, 0);
//commit
SharedPreferences.Editor editor = mSettings.edit();
editor.putString(DATA_TAG, data);
editor.commit();
//clear
SharedPreferences.Editor editor = mSettings.edit();
editor.clear();
editor.commit();
//get
String data= mSettings.getString(DATA_TAG, null);
If you would like to store your data not only on your local device but share this data across the devices for the same user or even across different platforms you can use a simple API of Skiller SDK. I am ofcourse from Skiller, for full disclosure.
If you're looking to only store the data locally, use SharedPreferences. If you're looking to have this data persist across multiple devices (always available for this user), check out Swarm's Cloud Data, which provides a simple set/get (like SharedPreferences) for storing data in the cloud.
This is what SharedPreferences is all about.
Best way to implement is, store in shredpreferences, read it on lauch of your application. Shared Preference API. HEre is an example
on how to use SharedPreferences

Android SharedPreferences

I have 3 webviews in my search engine app.When the user enters his query, by default he gets Google results, followed by yahoo and Ask buttons at the bottom, on clicking either of them, he gets results for that query from those sites. Now I want to give the user the privilege to change the default result site. I have created 3 radiobuttons. Upon confirmation, say he chooses Yahoo, how can i set it as Yahoo till the next time he changes it to some other site,
Accessing data from SharedPreferences:
SharedPreferences sharedPref = getSharedPreferences("FileName",MODE_PRIVATE);
String webViewChoice = sharedPref.getString("userChoice","null");
if no choice was saved (in the case when the application is running for the first time), you'll get "null" in webViewChoice.
use this condition as you wish
Saving data in SharedPreferences:
SharedPreferences sharedPref = getSharedPreferences("FileName",MODE_PRIVATE);
SharedPreferences.Editor prefEditor = sharedPref.edit();
prefEditor.putString("userChoice",usersChoice);
prefEditor.commit();
I hope it helps.
Save the user's preference as default-engine=google by default in a shared preferences file.
On app loading, read the file and set the default engine during the app runtime. When user chooses a different engine as default, then update the preferences file.
Hope this helps.

Categories

Resources