我试图从Parse获取值,但即使在成功PUT(ting)之后,我似乎无法获得GET。该课程的数据是'而价值是“学校开放”。 (布尔类型)。我究竟做错了什么?我想要做的是获取schoolOpen的布尔值(来自Parse)并将其传递给schoolOpenStatus。
package com.t99sdevelopment.centralized;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageButton;
import android.widget.TextView;
import com.parse.GetCallback;
import com.parse.Parse;
import com.parse.ParseException;
import com.parse.ParseObject;
import com.parse.ParseQuery;
public class HomeScreen extends AppCompatActivity {
public static boolean schoolOpenStatus = false;
public static String testText = "It hasn't been changed.";
ParseObject data = new ParseObject("data");
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_homescreen);
setTheme(R.style.AppTheme);
setActionBarText("Home");
parseInit();
parseGet(null);
TextView parseTestText = (TextView) findViewById(R.id.parseTest);
if (schoolOpenStatus == true){
parseTestText.setText("IT'S OPEN");
} else {
parseTestText.setText("SNOW DAY WOOT");
}
System.out.print(schoolOpenStatus);
}
private void parseInit(){
Parse.enableLocalDatastore(this);
Parse.initialize(this, "epEwSw0NR98IbT5h0AlSpsqx0d43MvdxYPPdUIPP", "NvLTibN0IlZncqmzbIP0WYIpu3yNHzwIBS1klXiu");
DataStore.isOpen = true;
}
public void parseGet(View view){
ParseQuery<ParseObject> query = ParseQuery.getQuery("data");
query.getInBackground("zF3GAgdbi3", new GetCallback<ParseObject>() {
public void done(ParseObject object, ParseException e) {
if (e == null) {
schoolOpenStatus = data.getBoolean("schoolOpen");
} else {
// something went wrong
}
}
});
}
private void setActionBarText(String actionBarText){
TextView actionBar = (TextView) findViewById(R.id.toolbar_title);
actionBar.setText(actionBarText);
}
public void goToHome(MenuItem item){}
public void goToAnnouncements(MenuItem item){
Intent intentAnnouncements = new Intent(this, AnnouncementsScreen.class);
startActivity(intentAnnouncements);
}
public void goToSchedule(MenuItem item){
Intent intentSchedule = new Intent(this, ScheduleScreen.class);
startActivity(intentSchedule);
}
public void goToCalendar(MenuItem item){
Intent intentCalendar = new Intent(this, CalendarScreen.class);
startActivity(intentCalendar);
}
public void goToContactBook(MenuItem item){
Intent intentContactBook = new Intent(this, ContactBookScreen.class);
startActivity(intentContactBook);
}
public void goToFrontAndCentral(MenuItem item){
Intent intentFrontAndCentral = new Intent(this, FrontAndCentralScreen.class);
startActivity(intentFrontAndCentral);
}
public void goToMap(MenuItem item){
Intent intentMap = new Intent(this, MapScreen.class);
startActivity(intentMap);
}
public void goToAccount(MenuItem item){
Intent intentAccount = new Intent(this, AccountScreen.class);
startActivity(intentAccount);
}
}
此外,日志不断吐出:
(HTTPLog)-Static: isSBSettingEnabled false
答案 0 :(得分:1)
您从错误的schoolOpen
ParseObject
schoolOpenStatus = data.getBoolean("schoolOpen");
而不是使用done
回复ParseObject
object
schoolOpenStatus = object.getBoolean("schoolOpen");