简体   繁体   中英

PostMessage() alternative in Java(Android)

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

?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM