我想首先将数据保存在本地存储中,然后通过Parse将其同步到云数据库

时间:2016-02-03 18:14:52

标签: android parse-platform

您好我想在应用离线时本地保存数据,点击按钮,稍后在网络可用时同步。

我通过parse使用saveEventually()但是无法在按钮点击时保存数据。

请注意。当我点击按钮它执行两个功能,首先保存数据,然后打开第二个活动。并且它也会在新活动中将objectId意图。

public void nextQues(View view){ final ProgressDialog pdia = new ProgressDialog(StartFeedback.this); pdia.setMessage("Loading Ques 2...Please wait..."); pdia.show();

    final ParseObject newUser = new ParseObject("ArtofLiving");
    newUser.put("happinessIndex", textView.getText().toString());
    newUser.put("userName", ParseUser.getCurrentUser().getUsername());
    newUser.pinInBackground();
    newUser.saveEventually(new SaveCallback() {
        @Override
        public void done(ParseException e) {
            if (e == null) {
                String objectId = newUser.getObjectId();
                pdia.dismiss();
                StartFeedback.this.finish();
                Intent intent = new Intent(StartFeedback.this, QuesTwo.class);
                intent.putExtra("id", objectId);
                startActivity(intent);
            } else {
                Toast.makeText(StartFeedback.this, e.getMessage(), Toast.LENGTH_SHORT).show();
                pdia.dismiss();
                StartFeedback.this.finish();
                Intent intent = new Intent(StartFeedback.this, GreyGreen.class);
                startActivity(intent);
            }

        }
    });


}

0 个答案:

没有答案