Lock dialog from JNI code

I am writing an application that basically is a wrapper around a 250K JNI. JNI (game engine) has APIs like handle_penUp (int x, int y). Sometimes he has to request the user from inside handle_penUp () (via callbacks to Java code), so the dialog that I use to implement the request must be blocked.

I understand that the main thread of execution cannot be blocked. So I spawned a second thread that makes all JNI calls that can lead to callbacks that need to be blocked. Inside this second thread, when I need to set the lock dialog, I call startActivityForResult () and then acquire () on the semaphore. When onActivityResult () is called in the main thread, it calls release () on the same semaphore.

This works if my request is implemented as a new action, but not if I want to show Dialog () within an existing Activity. The log messages tell me that my thread needs a Looper. I add one - and I will add information about whether it works, but it seems to me that I'm going the wrong way. I need a recipe for creating lock dialogs (useful if only because every other platform has them, and so ported code will often work this way.)

+5
source share
2 answers

The sound is very close to the problem that I faced with setting the visible / invisible view from the sensor thread.

, ( )

, Handle Activity

public static final Handler handlerVisibility = new Handler() {
    public void handleMessage(Message msg) {
        int visibility = msg.getData().getInt("visibility");
        view.setVisibility(visibility);
    }
};

public static, ( , ).

, , , , gui, ^^

Message msg = MainActivity.handlerVisibility.obtainMessage();
    Bundle b = new Bundle();
            b.putInt("visibility", View.VISIBLE);
    msg.setData(b);
            MainActivity.handlerVisibility.sendMessage(msg);

GUI

,

+2

. , Android SDK, (.. , , , ..).

, , , - , , -, - , .

"", ? ? , , true, , , ?

0

All Articles