无法在parse.com云上保存数据?

时间:2015-12-22 19:22:18

标签: java android parse-platform

我目前正在尝试在parse.com云上保存数据。我在解析时编写了手册中指定的代码,但它仍然不能证明数据已传输到云中。任何想法可能是什么问题?

这是代码:

package com.example.sudelm.restaurants;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ListView;

import com.parse.Parse;
import com.parse.ParseObject;

public class MainActivity extends AppCompatActivity {
public ListView lst;
public Adapter adapter;
public Button Addres;
static final int ADD_RES_CONTENT_REQUEST = 0;
static final int RATE_REST = 1;
private Model m_model;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    //ParseCrashReporting.enable(this);
    Parse.enableLocalDatastore(this);

    Parse.initialize(this);

    ParseObject testObject = new ParseObject("TestObject");
    testObject.put("foo", "bar");
    testObject.saveInBackground();

    this.adapter = new Adapter(this);
    Addres = (Button)findViewById(R.id.addResButton);
    lst = (ListView)findViewById(R.id.listView);
    this.m_model = Model.getInstance(this);
    this.adapter.setM_list(m_model.getAllRecords());
    this.lst.setAdapter(adapter);


    this.lst.setOnItemClickListener(new ListView.OnItemClickListener() {

        public void onItemClick(AdapterView<?> a, View v, int position, long l) {
            Intent rr = new Intent(MainActivity.this, RateRestaurant.class);
            ResItem newItem = (ResItem) adapter.getItem(position);
            Bundle b = new Bundle();
            b.putString("title", newItem.title);
            b.putString("phone", newItem.phone);
            b.putString("address", newItem.adress);
            b.putString("desc", newItem.description);
            b.putBoolean("veg", newItem.veg);
            b.putFloat("rate", newItem.rating);
            b.putInt("position", position);
            rr.putExtra("ItemInfo", b);
            startActivityForResult(rr, RATE_REST);

        }
    });

    Addres.setOnClickListener(new Button.OnClickListener(){

        public void onClick(View v){
            startActivityForResult(new Intent(MainActivity.this, AddRestaurant.class), ADD_RES_CONTENT_REQUEST);


        }


    });

}

protected void onActivityResult(int requestCode, int resultCode, Intent data){
    if (requestCode == ADD_RES_CONTENT_REQUEST){
        if (resultCode == RESULT_OK){

            Bundle b = data.getBundleExtra("newItem");
            ResItem newItem = new ResItem(b.getString("title"),
                    b.getString("phone"),
                    b.getString("address"),
                    b.getString("desc"),
                    b.getBoolean("veg"));

            this.adapter.addItem(newItem);
            this.adapter.notifyDataSetChanged();
        }
    }
    else if(requestCode == RATE_REST){
        if (resultCode == RESULT_OK){
            Bundle b = data.getBundleExtra("UpdateRate");
            float rat = b.getFloat("rate");
            int pos = b.getInt("position");
            ((ResItem)adapter.getItem(pos)).rating = rat;
        }


    }

}
}

0 个答案:

没有答案