Differences between Android and j2's (2)

Source: Internet
Author: User
The last time we talked about the comparison between Android activity and the MIDlet of j2's, the two classes to be compared this time are the displayable class of j2's and the View class of Android.

When it comes to the displayable class, you may not have used it directly. However, canvas and form classes are very familiar to users who are programming on the mobile phones of j2s, they are essential for rendering the low-level user UI and the high-level user UI. Taking canvas as an example, j2s' encapsulation of a large number of methods that can be inherited and override (the painting (Graphics g) method must be rewritten ), the functions of these methods cover touch screen operation response, button response, and screen rendering. Through these methods, we can listen to user input and report different outputs to users, that is, refresh the screen display. The above functions are required for canvas as the UI.

The View class in Android is much more powerful. Screen rendering can be realized through the ondraw (canvas) method of override, And the touch screen response and button response can also be achieved by setting the default listener.

In principle, the two are very similar, but the difference is also great. I will list several differences I have found.
1. repaint () method and invalidate ()/postinvalidate () method
If you read the API, we can find that the repaint () of canvas in j2s and the invalidate ()/postinvalidate () of View in Android () the method implements the same function (almost all the explanatory text is the same ...), However, there is a difference between invalidate () and postinvalidate (): invalidate () can only be updated on the screen by calling ondraw (canvas) in the UI thread, while postinvalidate () it is necessary to do the same thing in the non-UI thread. This requires us to determine which call is in the current thread and which is not. This is especially important in multi-thread callback. In the j2s, you can directly call repaint ().

2. In addition, the display of the View class of Android is largely read from XML, including its layout and many attributes. We will discuss how to read it later. The canvas only needs DRAM draw, and the canvas cannot be set to the size (the fullscreenmode is not required), but the view can.

3. View constructor. We do not need to call it in activity, but displayable is required. In the activity, we need to use findviewbyid to retrieve the view from the XML, and then forcibly convert it to the child type of the view, while the canvas of j2_9 must be constructed.

4. In UI applications, Android is more powerful than j2's, because its view has many defined subclasses that can be called, just like those controls in winform programming in vs.net, it will be very convenient and beautiful. Because Android is open-source, many third-party controls will be available for us in the future, which greatly expands android. This will free us from those graphics. drawxxx functions and let our applicationsProgramBecome cool and cool.

I will talk about the comparison between view (Android) and displayable (j2_mainly canvas). I think there are a lot of things I haven't considered. I will try again later. I won't say much about how to read APIs and sample programs.

Next time, we should compare the bitmap class of Android and the image class of j2m2.

Thank you!

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.