views:

401

answers:

1

Hi,

I am rewriting the existing C++ application and adapting it for Android environment.

In the code there is a PostMessage statement:

PostMessage( bExitApp ? WM_CLOSE : WM_LOGIN, wParam, lParam );

Does anyone know what is the most appropriate way to achieve tha same result in Android (Java)?

Is it well enough to create two methods like OnLogin() and OnClose() the following way:

private void OnLogin(long arg0, long arg1)
{
//some logic here
}

private void OnClose(long arg0, long arg1)
{
//some logic here
}

and then write

if(bExitApp)
(
OnLogin(arg0, arg1)
)
else
{
OnClose(arg0, arg1)
}

?

Thanks!

+1  A: 

That may work. The difference is that postMessage runs after the event has been fully processed and you are back at the top of the event loop. You can simulate the behavior of PostMessage by using Handler.post(Runnable r) where you use the handler of the GUI thread.

hacken