回调中的Android Toast方法未显示

时间:2013-01-31 05:38:21

标签: android toast

我创建了这个类,但是我无法获得弹出消息,该消息应该在成功存储到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
            }
    });
}

1 个答案:

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

请参阅runOnUiThread