Can I use NativeActivity with ActivityGroup?

白昼怎懂夜的黑 提交于 2019-12-05 22:16:21

This time I found a workaround for it, and works fine. but just for the ndk demos.

on your ActivityGroup sub class onCreate method, write the following code.

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    LocalActivityManager lam = getLocalActivityManager();

    Intent intent = new Intent();
    intent.setClass(this, TeapotNativeActivity.class);

    Window window = lam.startActivity("xxx", intent);

    // reflect call "willYouTakeTheSurface"
    NativeActivity callback = JavaCalls.callMethod(window.getDecorView(), "willYouTakeTheSurface");
    if (callback != null) {
        window.takeSurface(null);
        getWindow().takeSurface(callback);
        getWindow().takeInputQueue(callback);
    }


    setContentView(window.getDecorView());

}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!