0

I have implemented a coachmark in onCreateOptionsMenu method in an activity.

/* Coachmark - preview */
        if (preview.isEnabled(uuserID)) {
            new runOnMainThread(() -> {
                    final View anchorView = findViewById(R.id.action_preview);
                    if (anchorView != null) {
                        new CoachMark.Builder(PreviewActivity.this, anchorView, CoachMarkType.CoachMarkDirection.TOP)
                                .setText(R.string.hello_tooltip)
                                .setTextStyleId(R.style.AppStatusBarTextStyle)
                                .setRadius(MiscUtils.dpToPixel(PreviewActivity.this, 4))
                                .dismissOnTouch(true)
                                .dismissOnTouchOutside(true)
                                .build()
                                .show();
                    }
            });
        }

public static Task<Void> runOnMainThread(@NonNull Runnable runnable) {
    return runOnExecutor(runnable, Task.UI_THREAD_EXECUTOR, null);
}

When the activity is in focus, it loads a file and also creates the options Menu for the activity. I was invoking the coachmark from the createOptionsMenu and the coachmark is not getting displayed when I run the thread using the runOnMainThread() and is getting displayed when using Handler().post(). Any reasons why and when to use the handler and when to use the runOnMainThread().

Angus
  • 12,133
  • 29
  • 96
  • 151
  • Does this answer your question? [Why to use Handlers while runOnUiThread does the same?](https://stackoverflow.com/questions/12618038/why-to-use-handlers-while-runonuithread-does-the-same) – Uuu Uuu Sep 16 '20 at 07:39
  • No. One works and other don't. I am trying to understand the difference between both. Why the runOnMainThread didn't work in the above scenario. Is it possible to use runOnMainThread in the above scenario. – Angus Sep 16 '20 at 07:54
  • 1
    `runOnUiThread` internally uses handler to post the Job. What executer framework you are using here ? i am not familiar with `Task.UI_THREAD_EXECUTOR` .. Is it `bolts-framework` ? if yes then add a tag .. – ADM Sep 16 '20 at 08:11
  • @ADM : Have added the tag. – Angus Sep 16 '20 at 09:33
  • Does this answer your question? [What is the difference between runOnUiThread method and Handler? Which one is the best to use?](https://stackoverflow.com/questions/52152906/what-is-the-difference-between-runonuithread-method-and-handler-which-one-is-th) – shb Sep 16 '20 at 09:37
  • No. Its runOnMainThread, not runOnUIThread.Thanks for the link. – Angus Sep 16 '20 at 09:57

0 Answers0