質問編集履歴
3
コードの修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -220,21 +220,6 @@
|
|
220
220
|
}
|
221
221
|
|
222
222
|
//もしデータがdoGetDemoであることが確認できたら、その後に誰々さんようこそは重複登録ができなくなった後でやる。
|
223
|
-
|
223
|
+
|
224
|
-
/**
|
225
|
-
NCMBObject obj = new NCMBObject("TestClass");
|
226
|
-
obj.setObjectId("getTestObjectId");
|
227
|
-
obj.fetchInBackground(new FetchCallback<NCMBObject>() {
|
228
224
|
|
229
|
-
@Override
|
230
|
-
public void done(NCMBObject object, NCMBException e) {
|
231
|
-
if (e != null) {
|
232
|
-
//エラー時の処理
|
233
|
-
} else {
|
234
|
-
//取得成功時の処理
|
235
|
-
}
|
236
|
-
}
|
237
|
-
});
|
238
|
-
**/
|
239
|
-
|
240
225
|
```
|
2
コードの追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -67,4 +67,174 @@
|
|
67
67
|
|
68
68
|
}
|
69
69
|
|
70
|
+
```しっかりエラーがなく実行できたログイン、新規登録のコードです。
|
71
|
+
```java
|
72
|
+
package ncmbdataquick.mbaas.com.nifty.datastorequickstart;
|
73
|
+
|
74
|
+
import android.app.Activity;
|
75
|
+
import android.app.AlertDialog;
|
76
|
+
import android.content.Intent;
|
77
|
+
import android.os.Bundle;
|
78
|
+
import android.view.View;
|
79
|
+
import android.view.Menu;
|
80
|
+
import android.view.MenuItem;
|
81
|
+
import android.widget.Button;
|
82
|
+
|
83
|
+
import com.nifty.cloud.mb.core.DoneCallback;
|
84
|
+
import com.nifty.cloud.mb.core.FindCallback;
|
85
|
+
import com.nifty.cloud.mb.core.NCMB;
|
86
|
+
import com.nifty.cloud.mb.core.NCMBException;
|
87
|
+
import com.nifty.cloud.mb.core.NCMBObject;
|
88
|
+
import com.nifty.cloud.mb.core.NCMBQuery;
|
89
|
+
|
90
|
+
import java.util.List;
|
91
|
+
|
92
|
+
public class MainActivity extends Activity {
|
93
|
+
|
94
|
+
@Override
|
95
|
+
protected void onCreate(Bundle savedInstanceState) {
|
96
|
+
super.onCreate(savedInstanceState);
|
97
|
+
setContentView(R.layout.activity_main);
|
98
|
+
|
99
|
+
|
100
|
+
//**************** APIキーの設定とSDKの初期化 **********************
|
101
|
+
NCMB.initialize(this, "");
|
102
|
+
|
103
|
+
|
104
|
+
Button newUserAddButton = (Button) findViewById(R.id.NewUserAdd);
|
105
|
+
newUserAddButton.setOnClickListener(new View.OnClickListener() {
|
106
|
+
|
107
|
+
//ここに新規登録へのボタンを押した時を作る
|
108
|
+
@Override
|
109
|
+
public void onClick(View v) {
|
110
|
+
|
111
|
+
// ボタン1が押された場合
|
112
|
+
if (v.getId() == R.id.NewUserAdd) {
|
113
|
+
|
114
|
+
Button sendButton = (Button) findViewById(R.id.NewUserAdd);
|
115
|
+
Intent intent = new Intent(getApplication(), ActivitySecond.class);
|
116
|
+
startActivity(intent);
|
117
|
+
}
|
118
|
+
}
|
119
|
+
});
|
120
|
+
//この下にもう一つのリスナー
|
121
|
+
|
122
|
+
Button toLoginButton=(Button)findViewById(R.id.LoginCheckAnswer);
|
123
|
+
toLoginButton.setOnClickListener(new View.OnClickListener() {
|
124
|
+
|
125
|
+
//ここにログインへのボタンを押した時を作る
|
126
|
+
@Override
|
127
|
+
public void onClick(View v) {
|
128
|
+
if (v.getId() == R.id.LoginCheckAnswer) {
|
129
|
+
Intent intent = new Intent(getApplication(), ActivityThird.class);
|
130
|
+
startActivity(intent);
|
131
|
+
}
|
132
|
+
}
|
133
|
+
});
|
134
|
+
//この上に
|
135
|
+
}
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
@Override
|
140
|
+
public boolean onCreateOptionsMenu (Menu menu){
|
141
|
+
// Inflate the menu; this adds items to the action bar if it is present.
|
142
|
+
getMenuInflater().inflate(R.menu.menu_main, menu);
|
143
|
+
return true;
|
144
|
+
}
|
145
|
+
|
146
|
+
@Override
|
147
|
+
public boolean onOptionsItemSelected (MenuItem item){
|
148
|
+
// Handle action bar item clicks here. The action bar will
|
149
|
+
// automatically handle clicks on the Home/Up button, so long
|
150
|
+
// as you specify a parent activity in AndroidManifest.xml.
|
151
|
+
int id = item.getItemId();
|
152
|
+
|
153
|
+
//noinspection SimplifiableIfStatement
|
154
|
+
if (id == R.id.action_settings) {
|
155
|
+
return true;
|
156
|
+
}
|
157
|
+
|
158
|
+
return super.onOptionsItemSelected(item);
|
159
|
+
}
|
160
|
+
|
161
|
+
//トップ画面のいらないであろうボタン
|
162
|
+
public void doStartDemo(View view) {
|
163
|
+
final NCMBObject obj = new NCMBObject("TestClass");
|
164
|
+
obj.put("message", "Hello, NCMB!");
|
165
|
+
obj.saveInBackground(new DoneCallback() {
|
166
|
+
@Override
|
167
|
+
public void done(NCMBException e) {
|
168
|
+
if (e != null) {
|
169
|
+
//保存失敗
|
170
|
+
new AlertDialog.Builder(MainActivity.this)
|
171
|
+
.setTitle("Notification from Nifty")
|
172
|
+
.setMessage("Error:" + e.getMessage())
|
173
|
+
.setPositiveButton("OK", null)
|
174
|
+
.show();
|
175
|
+
|
176
|
+
} else {
|
177
|
+
//保存成功
|
178
|
+
new AlertDialog.Builder(MainActivity.this)
|
179
|
+
.setTitle("Notification from Nifty")
|
180
|
+
.setMessage("Save successfull! with ID:" + obj.getObjectId())
|
181
|
+
.setPositiveButton("OK", null)
|
182
|
+
.show();
|
183
|
+
|
184
|
+
}
|
185
|
+
}
|
186
|
+
});
|
187
|
+
|
188
|
+
}
|
189
|
+
|
190
|
+
|
191
|
+
//get(検索)
|
192
|
+
//トップ画面のいらないだろうボタン
|
193
|
+
public void doGetDemo(View view) {
|
194
|
+
//TestClassを検索するためのNCMBQueryインスタンスを作成
|
195
|
+
NCMBQuery<NCMBObject> query = new NCMBQuery<>("TestClass");
|
196
|
+
//keyというフィールドがvalueとなっているデータを検索する条件を設定
|
197
|
+
query.whereEqualTo("message", "Hello, NCMB!");
|
198
|
+
//データストアからデータを検索
|
199
|
+
query.findInBackground(new FindCallback<NCMBObject>() {
|
200
|
+
@Override
|
201
|
+
public void done(List<NCMBObject> results, NCMBException e) {
|
202
|
+
if (e != null) {
|
203
|
+
|
204
|
+
|
205
|
+
} else {
|
206
|
+
|
207
|
+
new AlertDialog.Builder(MainActivity.this)
|
208
|
+
.setTitle("Notification from Nifty")
|
209
|
+
.setMessage("Get successfull!"+results)
|
210
|
+
.setPositiveButton("OK", null)
|
211
|
+
.show();
|
212
|
+
//検索成功時の処理
|
213
|
+
}
|
214
|
+
|
215
|
+
|
216
|
+
|
217
|
+
}
|
218
|
+
});
|
219
|
+
}
|
220
|
+
}
|
221
|
+
|
222
|
+
//もしデータがdoGetDemoであることが確認できたら、その後に誰々さんようこそは重複登録ができなくなった後でやる。
|
223
|
+
//だからこのコードはいらない
|
224
|
+
/**
|
225
|
+
NCMBObject obj = new NCMBObject("TestClass");
|
226
|
+
obj.setObjectId("getTestObjectId");
|
227
|
+
obj.fetchInBackground(new FetchCallback<NCMBObject>() {
|
228
|
+
|
229
|
+
@Override
|
230
|
+
public void done(NCMBObject object, NCMBException e) {
|
231
|
+
if (e != null) {
|
232
|
+
//エラー時の処理
|
233
|
+
} else {
|
234
|
+
//取得成功時の処理
|
235
|
+
}
|
236
|
+
}
|
237
|
+
});
|
238
|
+
**/
|
239
|
+
|
70
240
|
```
|
1
接続が上手くいかずエラーの出るコードをのせました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -7,4 +7,64 @@
|
|
7
7
|
とでます。
|
8
8
|
|
9
9
|
この前に作ったログインアプリのコードの一部を使ったのですが、なぜなのでしょうか?
|
10
|
-
前にはできました。
|
10
|
+
前にはできました。
|
11
|
+
|
12
|
+
接続が上手くいかないコードです。
|
13
|
+
```java
|
14
|
+
package com.example.kanehiro.memo;
|
15
|
+
|
16
|
+
import android.content.Intent;
|
17
|
+
import android.os.Bundle;
|
18
|
+
import android.support.v7.app.AppCompatActivity;
|
19
|
+
import android.view.View;
|
20
|
+
import android.widget.Button;
|
21
|
+
|
22
|
+
import com.nifty.cloud.mb.core.DoneCallback;
|
23
|
+
import com.nifty.cloud.mb.core.FindCallback;
|
24
|
+
import com.nifty.cloud.mb.core.NCMB;
|
25
|
+
import com.nifty.cloud.mb.core.NCMBException;
|
26
|
+
import com.nifty.cloud.mb.core.NCMBObject;
|
27
|
+
import com.nifty.cloud.mb.core.NCMBQuery;
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
public class MainActivity extends AppCompatActivity {
|
32
|
+
|
33
|
+
@Override
|
34
|
+
protected void onCreate(Bundle savedInstanceState) {
|
35
|
+
super.onCreate(savedInstanceState);
|
36
|
+
setContentView(R.layout.activity_main);
|
37
|
+
|
38
|
+
|
39
|
+
//**************** APIキーの設定とSDKの初期化 **********************
|
40
|
+
NCMB.initialize(this, "");
|
41
|
+
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
Button newUserAddButton = (Button) findViewById(R.id.button);
|
46
|
+
newUserAddButton.setOnClickListener(new View.OnClickListener() {
|
47
|
+
|
48
|
+
//ここに新規登録へのボタンを押した時を作る
|
49
|
+
@Override
|
50
|
+
public void onClick(View v) {
|
51
|
+
|
52
|
+
// ボタン1が押された場合
|
53
|
+
if (v.getId() == R.id.button) {
|
54
|
+
|
55
|
+
Button sendButton = (Button) findViewById(R.id.button);
|
56
|
+
Intent intent = new Intent(getApplication(), ActivitySecond.class);
|
57
|
+
startActivity(intent);
|
58
|
+
}
|
59
|
+
}
|
60
|
+
});
|
61
|
+
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
}
|
66
|
+
|
67
|
+
|
68
|
+
}
|
69
|
+
|
70
|
+
```
|