[high]android application development of the intent of the magical

Source: Internet
Author: User
<span id="Label3"></p><p><p>I believe that Android application development of friends to intent components are already quite familiar with, here I summarize the intent of the magical, I hope to help you.</p></p><p><p></p></p><p><p><strong>Intent to write your own Android main interface</strong></p></p><p><p>As we all know, Android's main interface name is laucher2, powerful, it will run after Android launch, but also all other applications of the entry Program. So how do you get your application to take the place of Laucher2 and become the main interface of the Android system? In fact, it is very simple to say, then, I will come to uncover the mystery of the People.</p></p><p><p>first, Let's take a look at the intent declaration of an ordinary application:</p></p><p><p></p></p> <ol class="dp-j" start="1"> <ol class="dp-j" start="1"> <li><intent-filter></li> <li class="alt"><action android:name=<span class="string">"android.intent.action.MAIN"/></span></li> <li><category android:name=<span class="string">"android.intent.category.LAUNCHER"/></span></li> <li class="alt"></intent-filter></li> </ol> </ol><p><p>Does it look familiar? yes, This code is the intent declaration of the corresponding activity in androidmanifest.xml, and I believe that the intent declaration of the application that you are currently abbreviated is like This. Probably a lot of people will have the following understanding of the two lines of code:</p></p><p><p></p></p><p><p>The second line <action android:name=<span class="string">"android.intent.action.MAIN"/> indicates that the activity is the main activity of the current application, The second line indicates that the current activity is loaded in Lancher. </span></p></p><p><p>This is true, but in fact, there is a simpler way of understanding it. here, please allow me to sell a Xiaoguanzi First. Let's keep looking down.</p></p><p><p>Now that we want our own application to replace Laucher's location, Let's take a look at Lancher's intent Statement:</p></p><p><p></p></p> <ol class="dp-j" start="1"> <ol class="dp-j" start="1"> <li class="alt"><intent-filter>   </li> <li>          <action android:name=<span class="string"> "android.intent.action.MAIN"  / >   </span> </li> <li class="alt">        <category  Android:name=<span class="string"> "android.intent.category.HOME"/>   </span> </li> <li>          <category android:name=<span class="string"> " Android.intent.category.DEFAULT " />   </span> </li> <li class=" alt ">         <category android:name=<span class="string"> "android.intent.category.MONKEY"  />   </span> </li> <li>     </intent-filter>  </li> </ol> </ol><p><p>of course, to see this piece of code, you have to have Laucher source Code. (for Android Source code issues, the previous article has been mentioned many times, the source code is really a good thing, whether for the application developers or for the Bottom-level developers or for Android enthusiasts, will benefit, So here again we recommend that you do not just limit the use of the Android SDK and AVD for the development of applications, regardless of whether you have time, the next source code is always no harm. )</p></p><p><p></p></p><p><p>Do you see the difference between the two intent statements? yes, when it comes to <category android:name=<span class="string">"android.intent.category.HOME"/>, Our app becomes the same as Lancher (of course, I mean just the main interface, laucher's function is too strong to become the main interface of the Android system, and when we press the home button, there will be a selection interface, is it found that your application and Laucher appear in the selection box? If so, congratulate you, functionally, that you have Achieved. If you do not see, please email me [email protected]. </span></p></p><p><p>however, the so-called mountain does not allow two tigers, while there are two main interface exist of course not what we want.</p></p><p><p>If you have the Android source code, you can even delete the laucher, directly compiled your own application into the Android system, so that the system will be launched directly to run your application, and your application will be rushes, It is logical to become the main interface of the system, and when you press the home button, you will jump to the main activity of your application!!</p></p><p><p>If you are just a functional suitor, then you can turn off this page to try out the above Features.</p></p><p><p>If you are a more curious person, then please follow me to look Down.</p></p><p><p>As I said earlier, the understanding of the intent statement is a Problem. In fact, you can have a better understanding of the way, of course, this should be based on your Android system startup process has a certain understanding of the Basis.</p></p><p><p>Simply put, intent is actually a conditional filter, the activity of the intent declaration of each can be used as a filter, the more items, filter conditions are stronger, the easier to Locate. It is easier for a friend who believes in this principle to learn a database. You can put all the activity in the entire Android system together as a database, and intent itself is a select statement, each of which is a filter, and what is left after filtering is the activity that will be called. When the filter is strong enough or the filter is special, the last thing left is only one activity, then the system will not hesitate to start it, when the filter is not enough to allow more activity after filtering, All activity that satisfies these conditions is listed by a ListView to let you Choose.</p></p><p><p>Believe that the principle of everyone has been very clear, then the above-mentioned function is very good understanding. yes, Android will have a Packagemanager selection system that meets the filtering criteria when booting up:</p></p><p><p></p></p> <ol class="dp-j" start="1"> <ol class="dp-j" start="1"> <li> <action android:name=<span class="string"> "android.intent.action.MAIN"  />   </span> </li> <li class="alt">        < Category android:name=<span class="string"> "android.intent.category.HOME"/>   </span> </li> <li>         <category android:name=<span class="string"> " Android.intent.category.DEFAULT " />   </span> </li> <li class=" alt ">         <category android:name=<span class="string"> "android.intent.category.MONKEY"  />   </span> </li> </ol> </ol><p><p>Activity as the first activity of the system startup, that is, the main interface, any activity that satisfies this filter will go to the candidate list, and if there is only one person on the candidate list, then it is an honor to win without a fight, you are the main interface of the System. If there are more than one person on the shortlist (for example, Laucher and your own application), then go into a brutal "poll", which is the User's choice, and the system will start who you choose. But unlike popular elections, the election results usually have a certain term, and the election term for the main interface is very short, and when you press the home button or reboot the system, the system will reschedule the Poll. If you want to become the main interface forever, then the only way is--yes, although very cruel, but have to say--just, kill it ... Or harmony, you can let it live, but also must be relegated to the ordinary or to the frontier, the specific means of implementation is--to change its intent statement, so that it does not meet the main interface of this filter Condition.</p></p><p><p></p></p><p><p>Throughout the intent magical chapter, This chapter is quite special, because although all the chapters use the principle of basic similarities, that is, I said the principle, but the subsequent chapters of the intent filter conditions can be defined by the user, manual modification, and only this is not changed, You can only decide to adapt or not adapt to the filter, not to change the filter, as you can only adapt to the society, but it is difficult to change it-perhaps not, but temporarily can find a way ...</p></p><p><p>Sometimes it's true that life and computer have so many similarities ....</p></p><p><p>[high]android application development of the intent of the magical</p></p></span>

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.