简体   繁体   中英

Android: addContentView() doesn't appear until screen state changes

I am working adding a video on top of a currently running activity. I have managed to achieve this using the following:

this.surface    = new SurfaceView(getApplicationContext());
this.surface.getHolder().addCallback(this);
WindowManager.LayoutParams params = new WindowManager.LayoutParams();
params.height       = 500;
params.width        = 500;
this.activity.addContentView(surface, params);

I then attach the MediaPlayer to the SurfaceHolder gotten from this.surface. It works exactly as I need it to, except for one thing: the SurfaceView does not appear on-screen until after the screen state changes. I have to turn the screen off in order for the view to be added to the Activity. After that, everything works as expected.

Anyone have any clue why this is happening?

EDIT: Added more info from a comment to Kelvin Trinh.

It's an AIR Native Extension to use the native video component. The AIR application acts as the main activity, although I have no access to layouts or anything like that. this.activity is that main activity, taken from the extension context (how the AIR and Java apps communicate). I need the video to show on top of my app, which I have accomplished.

You didn't provide the class wrapping your code, but I guess it is a view in your main activity.

this.activity.addContentView(surface, params); denoted that you adding a surface view to your activity while you are on a specific view. This only adds a reference of your surface to the activity's view hierarchy, and it is updated only when the Activity reloads (recreated, restarted or resumed).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM