Summary of various bugs in the Android system

Source: Internet
Author: User

The Android system is still quite commonly used. So I studied the Android system and shared it with you here. I hope it will be useful to you. After learning about the principles of the Android system for a long time, I hope this article will teach you more things.

In the Layout interface, this program is actually no different from Snake. It also uses FrameLayout, and the main interface of the game is implemented by a custom View. Here is LunarView. Friends who have read the previous article may find that Snake's architecture is implemented by "timer + System Call onDraw.

The biggest drawback here is that onDraw is called by the Android system. We can only rely on it, but cannot control it on our own. This is like a black box. Of course, we can always make what we want, but we cannot control the details of what we do.

This is not good for games that are highly efficient, so the best solution is, of course, to draw this part of the work itself "contract" to come over and say goodbye to eating big pot meals, it entered the "co-production contract system" era. In addition, because the essence of the game is that there are some differences between two consecutive frames of images, it is necessary to continuously generate such a difference as long as some continuous events occur.

For example, the timer used in Snake is constantly generating this "differential source". Similarly, a thread is constantly running, this "source of difference" can also be generated continuously. If Layout and custom View used in Snake are a small weapon, SurfaceView is a heavy weapon for game development in android.

When we use the former, it is always easy to treat an object in the game, such as each square above, as a small component, while the latter does not have the concept of this division at all. In its eyes, all things are backgrounds, characters, and so on drawn in the Canvas ).

SurfaceView provides direct access to a graphic interface and controls the subview layer at the top of the interface. SurfaceView is provided for applications that need to directly draw pixels rather than using form components. An important concept and clue in the Android graphics system is surface. View and its subclass, such as TextView and Button)

Draw the image on the surface. Creates a Canvas object for each surface, but its attributes change frequently. This object is used to manage the drawing operations of a view on the surface, such as drawing points and draw lines. Note that The hierarchy will take care of correctly compositing usually appears at The top layer.

With the Surface any siblings of the SurfaceView that wocould normally appear on top of it. when using SurfaceView, we usually need to create, destroy, and monitor the changes. This requires SurfaceHolder. callback.

 
 
  1. Public void surfaceChanged (SurfaceHolder holder, int format, int width, int height)
  2. {
  3. Thread. setSurfaceSize (width, height );
  4. }
  5. Public void surfaceCreated (SurfaceHolder holder)
  6. {// Start the working thread to end
  7. Thread. setRunning (true );
  8. Thread. start ();
  9. }
  10. Public void surfaceDestroyed (SurfaceHolder holder)
  11. {
  12. Boolean retry = true;
  13. Thread. setRunning (false );
  14. While (retry)
  15. {
  16. Try
  17. {// Wait until the worker thread ends. The main thread ends.
  18. Thread. join ();
  19. Retry = false;
  20. }
  21. Catch (InterruptedException e)
  22. {
  23. }
  24. }
  25. }

This thread is implemented by a private Android system. It also has its own message queue processor, which is used to receive game status messages and display the current status on the screen. In Snake, this function is implemented by controlling whether the TextView it contains is displayed. In contrast, lunarread's message processing mechanism is more efficient ). With LunarView, most of LunarView's work is entrusted to the latter.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.