最近2018中文字幕在日韩欧美国产成人片_国产日韩精品一区二区在线_在线观看成年美女黄网色视频_国产精品一区三区五区_国产精彩刺激乱对白_看黄色黄大色黄片免费_人人超碰自拍cao_国产高清av在线_亚洲精品电影av_日韩美女尤物视频网站

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
Android之網(wǎng)絡(luò)數(shù)據(jù)存儲

 一、網(wǎng)絡(luò)保存數(shù)據(jù)介紹

可以使用網(wǎng)絡(luò)來保存數(shù)據(jù),在需要的時候從網(wǎng)絡(luò)上獲取數(shù)據(jù),進(jìn)而顯示在App中。

創(chuàng)新互聯(lián)公司致力于網(wǎng)站設(shè)計、成都做網(wǎng)站,成都網(wǎng)站設(shè)計,集團(tuán)網(wǎng)站建設(shè)等服務(wù)標(biāo)準(zhǔn)化,推過標(biāo)準(zhǔn)化降低中小企業(yè)的建站的成本,并持續(xù)提升建站的定制化服務(wù)水平進(jìn)行質(zhì)量交付,讓企業(yè)網(wǎng)站從市場競爭中脫穎而出。 選擇創(chuàng)新互聯(lián)公司,就選擇了安全、穩(wěn)定、美觀的網(wǎng)站建設(shè)服務(wù)!

用網(wǎng)絡(luò)保存數(shù)據(jù)的方法有很多種,對于不同的網(wǎng)絡(luò)數(shù)據(jù)采用不同的上傳與獲取方法。

本文利用LeanCloud來進(jìn)行網(wǎng)絡(luò)數(shù)據(jù)的存儲。

LeanCloud是一種簡單高效的數(shù)據(jù)和文件存儲服務(wù)。感興趣的可以查看網(wǎng)址:https://leancloud.cn/。關(guān)于LeanCloud的數(shù)據(jù)存儲使用方法可以在里面找到,本文不講述關(guān)于LeanCloud的使用,知識借助LeanCloud平臺舉一個在網(wǎng)絡(luò)上存儲數(shù)據(jù)的例子。

二、使用方法

1.上傳數(shù)據(jù)

Android之網(wǎng)絡(luò)數(shù)據(jù)存儲

        AVObject personObject = new AVObject(TABLENAME);
        personObject.put(NAME, person.name);
        personObject.put(AGE, person.age);
        personObject.put(INFO, person.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());
                }
            }
        });

Android之網(wǎng)絡(luò)數(shù)據(jù)存儲

2. 讀取數(shù)據(jù)

Android之網(wǎng)絡(luò)數(shù)據(jù)存儲

        AVQuery avQuery = new AVQuery<>(TABLENAME);
        avQuery.findInBackground(new FindCallback() {
            @Override            public void done(List 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);
                }
            }
        });

Android之網(wǎng)絡(luò)數(shù)據(jù)存儲

三、小案例

1.添加strings.xml文件
    Network
    獲取數(shù)據(jù)
    上傳數(shù)據(jù)
2.修改activity_main.xml文件

Android之網(wǎng)絡(luò)數(shù)據(jù)存儲

   xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context="com.zhangmiao.datastoragedemo.MainActivity">

    

        

        

            

Android之網(wǎng)絡(luò)數(shù)據(jù)存儲

3.添加NetworkDBManager類

Android之網(wǎng)絡(luò)數(shù)據(jù)存儲

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, person.name);
        personObject.put(AGE, person.age);
        personObject.put(INFO, person.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 avQuery = new AVQuery<>(TABLENAME);
        avQuery.findInBackground(new FindCallback() {
            @Override            public void done(List 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);
                }
            }
        });
    }
}

Android之網(wǎng)絡(luò)數(shù)據(jù)存儲

4.修改AndroidManifest.xml文件 
  
  
5.修改MainActivity

Android之網(wǎng)絡(luò)數(shù)據(jù)存儲

 android.net.*  MainActivity  AppCompatActivity  "MainActivity", "onCreate", "yMNUazdBt872mNtC9aSakjYy-gzGzoHsz", "d4vw3VYdMCjLpsXRhHTBRutC"= === =  Person("xiao", 23, "women"=  Person("zhao", 24, "men""MainActivity", "default"

Android之網(wǎng)絡(luò)數(shù)據(jù)存儲


文章題目:Android之網(wǎng)絡(luò)數(shù)據(jù)存儲
本文路徑:http://fisionsoft.com.cn/article/gogdoc.html