![【移動應(yīng)用開發(fā)技術(shù)】Android之網(wǎng)絡(luò)數(shù)據(jù)存儲_第1頁](http://file4.renrendoc.com/view/b431c5b3f76d83ce0a7a7ddee83e4e4c/b431c5b3f76d83ce0a7a7ddee83e4e4c1.gif)
![【移動應(yīng)用開發(fā)技術(shù)】Android之網(wǎng)絡(luò)數(shù)據(jù)存儲_第2頁](http://file4.renrendoc.com/view/b431c5b3f76d83ce0a7a7ddee83e4e4c/b431c5b3f76d83ce0a7a7ddee83e4e4c2.gif)
![【移動應(yīng)用開發(fā)技術(shù)】Android之網(wǎng)絡(luò)數(shù)據(jù)存儲_第3頁](http://file4.renrendoc.com/view/b431c5b3f76d83ce0a7a7ddee83e4e4c/b431c5b3f76d83ce0a7a7ddee83e4e4c3.gif)
![【移動應(yīng)用開發(fā)技術(shù)】Android之網(wǎng)絡(luò)數(shù)據(jù)存儲_第4頁](http://file4.renrendoc.com/view/b431c5b3f76d83ce0a7a7ddee83e4e4c/b431c5b3f76d83ce0a7a7ddee83e4e4c4.gif)
下載本文檔
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
【移動應(yīng)用開發(fā)技術(shù)】Android之網(wǎng)絡(luò)數(shù)據(jù)存儲
一、網(wǎng)絡(luò)保存數(shù)據(jù)介紹可以使用網(wǎng)絡(luò)來保存數(shù)據(jù),在需要的時候從網(wǎng)絡(luò)上獲取數(shù)據(jù),進而顯示在App中。用網(wǎng)絡(luò)保存數(shù)據(jù)的方法有很多種,對于不同的網(wǎng)絡(luò)數(shù)據(jù)采用不同的上傳與獲取方法。本文利用LeanCloud來進行網(wǎng)絡(luò)數(shù)據(jù)的存儲。LeanCloud是一種簡單高效的數(shù)據(jù)和文件存儲服務(wù)。感興趣的可以查看網(wǎng)址:/。關(guān)于LeanCloud的數(shù)據(jù)存儲使用方法可以在里面找到,本文不講述關(guān)于LeanCloud的使用,知識借助LeanCloud平臺舉一個在網(wǎng)絡(luò)上存儲數(shù)據(jù)的例子。二、使用方法
AVObject
personObject
=
new
AVObject(TABLENAME);
personObject.put(NAME,
);
personObject.put(AGE,
person.age);
personObject.put(INFO,
);
personObject.saveInBackground(new
SaveCallback()
{
@Override
public
void
done(AVException
e)
{
if
(e
==
null)
{
Log.v(TAG,
"put
data
success!");
}
else
{
Log.v(TAG,
"put
data
failed!error:"
+
e.getMessage());
}
}
});
AVQuery<AVObject>
avQuery
=
new
AVQuery<>(TABLENAME);
avQuery.findInBackground(new
FindCallback<AVObject>()
{
@Override
public
void
done(List<AVObject>
list,
AVException
e)
{
if
(e
==
null)
{
Log.v(TAG,
"get
data
success!");
String
message
=
"";
for
(int
i
=
0;
i
<
list.size();
i++)
{
String
name
=
list.get(i).getString(NAME);
int
age
=
list.get(i).getInt(AGE);
String
info
=
list.get(i).getString(INFO);
message
+=
"name:"
+
name
+
",age:"
+
age
+
",info:"
+
info
+
".\n";
}
textView.setText(message);
}
}
});三、小案例
<string
name="network">Network</string>
<string
name="get_data">獲取數(shù)據(jù)</string>
<string
name="put_data">上傳數(shù)據(jù)</string><?xmlversion="1.0"encoding="utf-8"?><android.support.design.widget.CoordinatorLayout
xmlns:android="/apk/res/android"
xmlns:tools="/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.zhangmiao.datastoragedemo.MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="@string/network"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/fab_margin"
android:layout_marginTop="@dimen/fab_margin"
android:orientation="horizontal">
<Button
android:id="@+id/network_put"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/put_data"/>
<Button
android:id="@+id/network_get"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/get_data"/>
</LinearLayout>
<TextView
android:id="@+id/table_info"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/app_name"/>
</LinearLayout></android.support.design.widget.CoordinatorLayout>package
com.zhangmiao.datastoragedemo;import
android.util.Log;import
android.widget.TextView;import
com.avos.avoscloud.AVException;import
com.avos.avoscloud.AVObject;import
com.avos.avoscloud.AVQuery;import
com.avos.avoscloud.FindCallback;import
com.avos.avoscloud.SaveCallback;import
java.util.List;/**
*
Created
by
zhangmiao
on
2016/12/22.
*/public
class
NetworkDBManager
{
private
static
final
String
TAG
=
"NetworkDBManager";
private
final
static
String
TABLENAME
=
"person";
private
final
static
String
NAME
=
"name";
private
final
static
String
AGE
=
"age";
private
final
static
String
INFO
=
"info";
public
void
putData(Person
person)
{
AVObject
personObject
=
new
AVObject(TABLENAME);
personObject.put(NAME,
);
personObject.put(AGE,
person.age);
personObject.put(INFO,
);
personObject.saveInBackground(new
SaveCallback()
{
@Override
public
void
done(AVException
e)
{
if
(e
==
null)
{
Log.v(TAG,
"put
data
success!");
}
else
{
Log.v(TAG,
"put
data
failed!error:"
+
e.getMessage());
}
}
});
}
public
void
getData(final
TextView
textView)
{
AVQuery<AVObject>
avQuery
=
new
AVQuery<>(TABLENAME);
avQuery.findInBackground(new
FindCallback<AVObject>()
{
@Override
public
void
done(List<AVObject>
list,
AVException
e)
{
if
(e
==
null)
{
Log.v(TAG,
"get
data
success!");
String
message
=
"";
for
(int
i
=
0;
i
<
list.size();
i++)
{
String
name
=
list.get(i).getString(NAME);
int
age
=
list.get(i).getInt(AGE);
String
info
=
list.get(i).getString(INFO);
message
+=
"name:"
+
name
+
",age:"
+
age
+
",info:"
+
info
+
".\n";
}
textView.setText(message);
}
}
});
}
}
<uses-permission
android:name="android.permission.INTERNET"
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年度建筑防水工程防水材料研發(fā)與市場調(diào)研合同
- 金華浙江金華市交通工程管理中心招聘編外人員筆試歷年參考題庫附帶答案詳解
- 遼寧2025年渤海大學招聘高層次人才92人筆試歷年參考題庫附帶答案詳解
- 湖南2025年湖南省生態(tài)環(huán)境廳直屬事業(yè)單位招聘44人筆試歷年參考題庫附帶答案詳解
- DB2103-T 008-2023 消防技術(shù)服務(wù)機構(gòu)從業(yè)規(guī)范
- 沈陽2025年遼寧沈陽遼中區(qū)四家事業(yè)單位面向區(qū)內(nèi)事業(yè)單位遴選18人筆試歷年參考題庫附帶答案詳解
- 常州2025年江蘇常州工學院高層次人才招聘60人(長期)筆試歷年參考題庫附帶答案詳解
- 2025年中國兩側(cè)擋渣器市場調(diào)查研究報告
- 2025年語音電路項目可行性研究報告
- 2025年耐高溫硅橡膠項目可行性研究報告
- 2025年電力鐵塔市場分析現(xiàn)狀
- GB 12158-2024防止靜電事故通用要求
- 《教育強國建設(shè)規(guī)劃綱要(2024-2035年)》全文
- 山東省濱州市2024-2025學年高二上學期期末地理試題( 含答案)
- 體育老師籃球說課
- 化學-江蘇省蘇州市2024-2025學年2025屆高三第一學期學業(yè)期末質(zhì)量陽光指標調(diào)研卷試題和答案
- 蛋雞生產(chǎn)飼養(yǎng)養(yǎng)殖培訓課件
- 運用PDCA降低住院患者跌倒-墜床發(fā)生率
- 海底撈員工手冊
- 2024CSCO小細胞肺癌診療指南解讀
- 立春氣象與生活影響模板
評論
0/150
提交評論