Abhishek
Abhishek

Reputation: 1

Android Toast method in callback not shown

I created this class but I am not able to get pop up message which should be generated after success in storing in 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
            }
    });
}

Upvotes: 0

Views: 1915

Answers (1)

Matthieu
Matthieu

Reputation: 16407

Do you know if the success function will be called on the UI thread?

If not, you should change it like this:

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

See runOnUiThread

Upvotes: 2

Related Questions