Discover android data storage best practices, include the articles, news, trends, analysis and practical advice about android data storage best practices on alibabacloud.com
());Where the database path is required to pass in the database name, the return value is as follows:08-26 08:04:01.049:debug/temppjactivity (): cont.getcachedir () =/data/data/com.study/cache08-26 08:04:01.049:debug/temppjactivity: Cont.getdatabasepath ("temp") =/data/data/com.study/databases/temp08-26 08:04:01.099:d
This time can and see very uncomfortable sharedpreferences say goodbye. The usage is disgusting. Save the fart big point data also uses commit.The end of the groove, on the codeLocalstorage.javaImport Java.io.file;import Java.io.fileinputstream;import Java.io.filenotfoundexception;import Java.io.fileoutputstream;import Java.io.ioexception;import Java.io.outputstream;import Java.io.unsupportedencodingexception;import Java.net.urldecoder;import Java.net
-}The second step is to test the code1 Packagecom.yxh.androidshareprefences01;2 3 ImportJava.util.Map;4 5 Importandroid.app.Activity;6 ImportAndroid.content.Context;7 Importandroid.content.SharedPreferences;8 Importandroid.test.AndroidTestCase;9 ImportAndroid.util.Log;Ten One Public classMyTestextendsAndroidtestcase { A Private StaticString tag= "MyTest"; - - PublicMyTest () { the //TODO auto-generated Constructor stub - } - //test
1. SharedPreferences is a lightweight storage class on the Android platform. It is mainly used to save some common configuration information. The following table lists the supported types. This method is the simplest method used in Android to read and write external data. It uses the Map
Sharedpreferences simple data storage, my understanding is similar to the Windows INI fileCan store many types, write a small exampleActivity_main.xmlLinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Xmlns:tools= "Http://schemas.android.com/tools"Android:id= "@+id/linearlayout1"Android:layout_width= "Match_parent"Android:layout_height= "Match
1. data file access operationWe can access the data to the default storage address for Android app data, with the address: installation package/data/data/1) Write
Sharedpreferences is a tool class for storing simple data in Android. It can be imagined that it is a small cookie that stores simple data types (boolean, int, float, long, and string) in the application's private directory by means of a key-value pair (data/data/package nam
")); theToast.maketext ( This, id+ "|" +name+ "|" +age+ "|" +address, 0). Show (); - }Wuyi Break; the CaseR.id.id_databasebuttondelete: - //The same operation as in the previous article Wu Break; - Caser.id.id_databasebuttonupdate: About //The same operation as in the previous article $ Break; - - default: - Break; A } + } the -}XML file:1 LinearLayoutxmlns:android= "Ht
1. Data Persistence StorageAndroid offers 4 ways to store files: files (/data/data/),sharepreference(/data/data/ ),SQLite Database (/data/data/) and Content Provider.Android uses the "j
methods provided by Sharedpreferences.editor: We can see that the data types supported by Sharedpreferences are: boolean, float, int, long, string, string, type set.Simple Use Example:1 sharedpreferences preferences = getsharedpreferences ("Sharedname", mode_private); 2 sharedpreferences.editor Editor = preferences.edit (); 3 editor.putstring ("Key", "abc"); 4 editor.commit ();Note: The fourth line of code above is very important, without this code,
The Qiao woman is difficult to urge without rice, data is a program of flesh and blood, but where does Android data exist? Android provides four ways to store data: sqlite/contentprovider/file/sharedpreferencesBecause the basic operation of the
In Android, we can put some data directly in the form of a file to be present in the device. For example: Some text files, PDF files, audio and video files and pictures. Android provides a way to read and write files.The standard Java file input stream (FileInputStream) is obtained through the Context.openfileinput () method, and the standard Java file output str
is a View object
Baseadapter
Two methods that must be implemented
First one//系统调用此方法,用来获知模型层有多少条数据@Overridepublic int getCount() { return people.size();}
A second//系统调用此方法,获取要显示至ListView的View对象//position:是return的View对象所对应的数据在集合中的位置@Overridepublic View getView(int position, View convertView, ViewGroup parent) { System.out.println("getView方法调用" + position); TextView tv = new TextView(MainActivity.this); //拿到集合中的元素 Person p = people.get(position);
Pop Up ToastYou can get the control object first in OnCreateThe package name of the/data/data/program/file read/write under this directory may become unreliable due to changes in the package name.This can be an activity, or it can be a contextThis.getfiledir (); data/data/Package Name/filesFileSharedUse the API to dyna
Com.example.data_storage_ Share. R;import Com.lc.data_storage_share.sharepreference.loginservice;import Android.os.bundle;import Android.app.activity;import Android.view.menu;import Android.view.view;import Android.view.View.OnClickListener; Import android.widget.button;import android.widget.checkbox;import android.widget.edittext;/* * unit tests need to be in the manifest file */ public class Mainactivity extends Activity {private button button1;//login private button button2;//Cancel private
Best practices of observer mode on android and best practices of android
In the previous article, I introduced the definition and some basic concepts of the observer mode. The observer mode is widely used in android development, such as monitoring and broadcasting of
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.