开发者

Android: passing object from activy to view

开发者 https://www.devze.com 2023-03-22 18:43 出处:网络
M开发者_如何学运维y activity load data from res.raw To give those datas to the view, I\'ve added a param to the view construtor

M开发者_如何学运维y activity load data from res.raw

To give those datas to the view, I've added a param to the view construtor

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    System.loadLibrary("engine-2d");

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
            WindowManager.LayoutParams.FLAG_FULLSCREEN );

    if (_engine == null)
    {
        Display display = getWindowManager().getDefaultDisplay(); 
        int width = display.getWidth();
        int height = display.getHeight();       

        byte[] scene;
        int scene_size = 0;
        try {
            InputStream ins = getResources().openRawResource(R.raw.package_test);
            scene_size = ins.available(); 
            scene = new byte[scene_size]; 
            ins.read(scene); 
            ins.close(); 
        } catch (IOException e) {
            // Should never happen!
            throw new RuntimeException(e);
        }

        _engine = new PlsEngine2D(scene, scene_size, width, height);
    }

    setContentView(new PlsSurface2D(this, _engine));
}


@Override
public void onDestroy() {
    super.onDestroy();
    _engine.DestroyEngine();
}

I don't know why but when I press the home button (the instance of my program is still in memory) and then I launch the application again, it crash.

In fact, PlsEngine2D use ndk to call C function that make malloc.

I do not exactly know where is the problem but I wonder if the malloc pointer are still correct !

Or may be this is my view! I give the _engine object to it. I wonder if when the view wake up it have the _engine param object again !

Is there another way to give my _engine object to the view ? Does the view can take the the _engine value to the activity ?


Could you post some code in your question please? I am not sure I am getting the whole picture.

Anyway, when you start an activity that is still in memory, the activity's following methods are called in the following order: onRestart(), onStart() and onResume().

Check this link for details


onResume() is called when the activity is still in the memory. It is not created again, since in onResume() you dont call setContentView() again.

0

精彩评论

暂无评论...
验证码 换一张
取 消