I solved the problem using handler as follows:
final Handler handler2 = new Handler();
Runnable runnable2 = new Runnable() {
@Override
public void run() {
Main.initLetterSetsPop();
}
};
where initLetterSetsPop()
is the function in the Main activity to show the popup window.
When I want to display the window in the onDraw() method, I simply use handler2.post(runnable2);