Many applications open the welcome interface for about 0.5 seconds, and then jump to the main interface, are implemented by latency. Bytes. Now I want to automatically preview the application as soon as I open it and draw a cross sign. That is, the preview is implemented by the button listener, and the preview is performed in the surfacecreated function. Define a surfacecallback class in mainactivity. As follows:
private final class SurfaceCallback implements Callback{ public void surfaceCreated(SurfaceHolder holder) { try{ camera = Camera.open(); Camera.Parameters parameters = camera.getParameters(); parameters.setPreviewSize(960, 540);
Parameters. setpreviewframerate (5); parameters. setpicturesize (1280,960); parameters. setjpegquality (80); camera. setparameters (parameters); camera. setpreviewdisplay (holder); camera. startpreview (); //} catch (exception e) {e. printstacktrace ();} new handler (). postdelayed (New runnable () {public void run () {// todo auto-generated method stub/* Cross */mdraw. setvisibility (view. visible); mdraw. drawline (); }}, 2000);} public void surfacechanged (surfaceholder holder, int format, int width, int height) {} public void surfacedestroyed (surfaceholder holder) {If (camera! = NULL) {Camera. Release (); camera = NULL ;}}}
The cross function is very simple. There are only two sentences.
Mdraw. setvisibility (view. Visible );
Mdraw. drawline ();
But these two statements are put in public void surfacecreated (surfaceholder holder ){...} The camera. startpreview () in this function is not found, because it seems that the top layer cannot be drawn before the underlying surfaceview preview screen is normal. Isn't it possible to draw at the same time in a thread ??? We can only say that the reason is unknown, so we can only use the delay.
New handler (). postdelayed (New runnable (){
Public void run (){
// Todo auto-generated method stub
/* Cross */
Mdraw. setvisibility (view. Visible );
Mdraw. drawline ();
}
},2000 );
The run () function is the task to be done after the delay is reached.
If you want to implement a boot welcome interface, you can write the following code in the run () function:
Intent intent = new intent (beginactivity. This, mainactivity. Class );
Beginactivity. This. startactivity (intent );
Beginactivity. Finish ();
Thanks to joim and Brother Gao for their guidance. Joim's code is awesome! Bytes. Android learning welcome to group: 248217350
Post note: It is better to add this code to the oncreate function! Added to the end of start preview, which is equal to an extended wait time!