I have an app that is based on NativeInterface, and so is primarily written in C++. I'd like to have some standard UI elements on the screen though, so I've written a small java class, with methods that should put UI on the screen when invoked. This way, I can just trigger it via JNI when I want things to show up on screen.
Here is the function:
public static void initLogWindow(Activity activity) {
class RunnableSetupWindow implements Runnable {
public Activity activity;
@Override
public void run() {
LinearLayout linear_layout = new LinearLayout(activity);
ScrollView scroll_view = new ScrollView(activity);
TextView text_view = new TextView(activity);
linear_layout.addView(scroll_view);
scroll_view.addView(text_view);
Window window = activity.getWindow();
window.takeSurface(null);
window.setContentView(linear_layout);
LoggingUtils.text_view = text_view;
text_view.setText("Hello world!");
}
}
RunnableSetupWindow setup_window = new RunnableSetupWindow();
text_view = null;
setup_window.activity = activity;
new Handler(Looper.getMainLooper()).post(setup_window);
}
Nothing shows up on the screen when I trigger it from JNI though. Very distressing. If I include Log statements in the function, they print out to the console just fine, so I know it's getting invoked. But it doesn't put anything on the screen of the device.
The weird part is, if I cut-and-paste this code into a random blank project, it does what I want. Text box appears. So clearly this code is capable make text-fields on the screen.
And if I go to my C++ code, and replace my JNI call (to invoke this method) with JNI equivalents of everything IN this method, then it ALSO works.
I've verified that the java method is being called. And the text field is clearly being made and is persisting - I can check and manipulate its text, and from the code's point of view, everything looks fine. It just doesn't show up on the screen.
Anyone have any idea why?