0

我创建了这个类,但我无法获得成功存储在 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
            }
    });
}
4

1 回答 1

2

你知道这个success函数是否会在 UI 线程上被调用吗?

如果没有,您应该像这样更改它:

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();
        });
}

runOnUiThread

于 2013-01-31T05:48:46.297 回答