Preparation for learning android mp3 PLAYER 1: activity

Source: Internet
Author: User

There is no doubt that activity is a very important thing to learn about android. 1: What is the activity component ?? It can be used to display a layout file. And responds to click and touch events on your layout file. It's a bit difficult. Let's talk about the image. If you have used an android mobile phone, you will see an interface. to exaggerate, all of them are activity, menu interface, setting interface, and operation interface, wait 2: some basic knowledge of the activity. The activity you write yourself needs to inherit the activity (if you don't even know the inheritance, I can't do it, this is already the most basic thing in android.) After an activity is started (started by the system through intent), what will the activity do ?? Let's take a look at the activity's life cycle onCreate (): when an activity is created, here we usually specify which layout file to use, as well as some initialization work, and so on onStart (): execute at the beginning. Some initialization code can also be put here onRestart (): when an activity () is stopped and other operations, onPause () will be executed (): when an activity loses its focus, it executes the task. As for what is the focus (the focus is available when you can click it, and the focus is lost when you cannot click it) onDestory (): when onResume () is executed during destruction to obtain the focus, as to what is the focus (the focus is available when you can click it, and the focus is lost when you cannot click it) onStop (): Stop, completely overwritten by other activities, exited, and so on. To familiarize yourself with the lifecycle of an activity, we suggest you write a test code. You can also check the lifecycle of the Baidu activity, so we will not expand it here (or else there will be too many things) go to MP3 Introduction: To create an MP3 file, you must display it on the UI, such as the playlist and playlist that we often see. Two activities are used in our activity: the first one to display the list of all the songs on the mobile phone. On the second playback control page, you can pause the playback. The last song and the next song are both activity, it shows two interfaces. If you need to add some beautiful girls to the background, just add background to the layout file. Here we will focus on logic, if you don't talk about these fancy things, how can you switch from the first activity to the second activity? We need to use our powerful Intent. Intent can implement the conversion of one activity to another. When you click a song, the playing interface needs to know that you are playing the magic horse. A series of Song information needs to be passed to the second interface. This is also done by Intent. How to do it, there are some in the Code. Let's see, there are not many points in the two, hey. Let's talk about the layout in a simple way: the first one is the layout of the listView. As for how to use the listView, you can give it an example in Baidu, the second layout is a general vertical layout and four horizontal la S (it seems that it is too late to read the code, it is very simple, you can understand it at a Glance.) Don't worry about how to play music, how to obtain the list, and so on. Next time, let's take a look at it, I believe most people can understand that playing music is the mediaplayer object that comes with android (which will be said later). The list content is obtained from the content provider (in the data provider. mediaPlayer) under that directory, you can export and view the table structure. The service is an implementation method that can still play music when we launch a player for other operations. The broadcast receiver is used for communication between the service and the activity, of course, you can also pause music when calling, and so on.

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.