Well, I tried "everything" that I could find and read everything I was looking for, the question is quite simple, but I do not understand what the problem is.
I work with NDK (native code in CPP).
I have a very simple activity that has OpenGL GLSurfaceView, where a very simple rendering was performed, at some point I would like to open a simple AlertDialog with two buttons.
Now I have tried many different approaches, basically falling into the idea of “messages are sent to the Java stream, where there is only a poll of messages, and then when it receives it, it sends a message with a handler to the main thread of the user interface, which starts the message handler, which creates an AlertDialog ".
I tried several other approaches, including just doing - for the test - "all from Java", sending a message to the handler inside the onTouchEvent () function of GLSurfaceView, as in the following code fragment:
@Override public boolean onTouchEvent(MotionEvent e) { if ( maskedAction == MotionEvent.ACTION_DOWN && isUiOn == false) { isUiOn = true; GilesTest2JNIActivity.theHandler.sendEmptyMessage(1); } return true; }
The handler that receives the message does the following:
public class GilesTest2JNIActivity extends Activity { GilesTest2JNIView mView; public static AlertDialog mTextInputDialog; private Context MyContext; public static Handler theHandler; public LayoutInflater mInflater = null; public Handler mHandler; @Override protected void onCreate(Bundle icicle) { super.onCreate(icicle); Log.i ("Giles OnCreate ","creating appl."); MyContext = this; mInflater = (LayoutInflater) getSystemService(MyContext.LAYOUT_INFLATER_SERVICE); mHandler = new Handler(){ public void handleMessage(Message msg){ AlertDialog.Builder builder = new AlertDialog.Builder(MyContext); Log.i ("handler","builder"); builder.setView(mInflater.inflate(R.layout.dialog_signin, null)); builder.setTitle("User - Login"); builder.setMessage("Please enter your username and pwd"); builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { GilesTest2JNILib.nativeSendInputText( "BBB", "AAA");
What happens, AlertDialog appears, everything works fine, but after a few seconds everything hangs, there are no error messages, nothing, but even rendering on GLSurfaceView () stops as .step () is not called anyway. Moreover, everything just freezes, doesn't causing any error messages and stays there almost always and / or sometimes gets into the "Application that is not responding".
This behavior, apparently, occurs on the Nexus 7 tablet, but on the other tablet I don’t have it, but after 4 or 5 times I start / close the dialog.
The only thing I managed to understand, it seems that at some point something stops receiving all kinds of touches and / or looks like “no window”, and / or some window disappears, in fact I can’t understand that going on.
I am re-adding some information that I just found out after extensive testing.
After receiving the classic basic OpenGL example, the one that simply draws a triangle and returns all this code, found that it all works, so let's go back to the square and try again in my code, which I started putting #ifdef in different places to chop off code fragments until I find the point of failure.
After a while I found out about this, it seems that the reason is not in this piece of code at all, but something related to the sound, which works in the background for me.
This is a very simple player based on OpenSL and a single player object, where it continuously plays a circular buffer in a loop, where samples are mixed, it seems that it all comes down to this bit of code:
// at this point we can enqueue the current chunk for playing theSize = AUDIO_DATA_CHUNK_SIZE*sizeof(SLint16);
AUDIO_DATA_CHUNK_SIZE - 128, this thing is designed to be played in a circular buffer loop in which samples are mixed, it is played continuously (sampling frequency 11.025 kHz).
If I turn off the sound while Alertdialog is working, everything works flawlessly.
I don’t know what happens if at some point you don’t see this:
12-19 18:56:52.418: W/InputConnectionWrapper.ICC(303): Timed out waiting on IInputContextCallback 12-19 18:56:52.418: I/InputDispatcher(150): Dropped event because it is stale. 12-19 18:56:52.418: I/InputDispatcher(150): Dropped event because it is stale. 12-19 18:56:52.418: I/InputDispatcher(150): Dropped event because it is stale.
It seems that in some way the reproduction of sound interferes with the input signal.