Android Development Tutorial-Actual Web page Source Viewer, Android Programmer essentials

Source: Internet
Author: User

This series of tutorials is dedicated to the quick learning of Android development, in accordance with the project approach, usually an article will do a small program. Improve your interest in learning.

On the one hand to summarize their own income, on the other hand can help more study colleagues through their own sharing.

Because of the coherence of knowledge, it is recommended to study in a twinkling. Directory Links: http://www.chengxiaoxiao.com/bozhu/1336.html

This tutorial by today's headlines-do the full-stack Siege Lion original debut, reproduced please indicate the source.

For a part-time job: please contact Wx:aiquanzhan

The GitHub source code is available at the end of the page.

First, the project description:

It is well known that every page that makes up a website is presented in HTML. We can view the source code by right-clicking on the page. View the HTML source code in detail. And as an Android, how should you get the Web source code? Let me slow down.

Second, the required technical points:

  1. Multithreading

  2. Network requests

  3. File stream

Three or one up development

3.1 Analysis: The development of Web page Source Viewer, the main steps are: According to the URL to make the request, parse the response stream to get the Web page source code, and then the page source code display.

3.2 Front Screen: Input click get button, automatically get the specified page source code is displayed below.

Put a code:

ScrollView: This is a control that sets a vertical scroll bar. So even TextView is particularly large. We can also swipe down to show the full contents of the TextView.

3.3 Initializing data and controls

3.4 Get web page source code, need to make network request operation. While network requests are time-consuming because of speed, Android supports direct network requests in earlier versions. Later versions can only be requested by opening another thread for the network.

So we need to. Opens a new thread.

How to open a new thread:

Communication between the new thread and the UI thread:

The UI interface is on a thread that is not on the same thread as this thread, and the two cannot communicate directly. Must be passed through a handler. Like the boss needs a secretary to upload the release. Handler is the role that has been played.

Initialize a handler:

How do I send a message to handler?

3.5 Making a network request:

Everything is ready: the beginning:

The stream object is converted to a string:

Of course, network requests need to be configured with permissions:

Open Androidmanifest File:

Final background processing code:

Effect:

Source Code Link: https://github.com/shellcheng/AndroidHTMLViewer

Original: Do the full stack siege Lion-Wx:aiquanzhan

Android Development Tutorial-Actual Web page Source Viewer, Android Programmer essentials

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.