我创建了这个类,但是我无法获得弹出消息,该消息应该在成功存储到stackmob后生成。
public class TaskActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
csuper.onCreate(savedInstanceState);
//setContentView(R.layout.TaskActivity;
setContentView(R.layout.activity_task);
StackMobAndroid.init(getApplicationContext(), 0, "010686ac-9fb2-4c70-bbec-c2d92ccdc39d");
Task myTask = new Task("Learn even more about StackMob", new Date(0));
myTask.save(new StackMobModelCallback() {
@Override
public void success() {
// the call succeeded
// Toast.makeText(this, "No camera on this device",0).show();
Toast msg = Toast.makeText(TaskActivity.this,
"i have done it", Toast.LENGTH_LONG);
msg.show();
}
@Override
public void failure(StackMobException e) {
// the call failed
}
});
}
答案 0 :(得分:1)
您知道是否会在UI线程上调用success
函数吗?
如果没有,你应该改变它:
public void success() {
// the call succeeded
TaskActivity.this.runOnUiThread(new Runnable() {
@Override
void run() {
Toast msg = Toast.makeText(TaskActivity.this,
"i have done it", Toast.LENGTH_LONG);
msg.show();
});
}