intent android application development of a magical

Android application development do believe friends of intent components are already quite familiar, here I summarize the magical intent, and we want to help.

Magical intent to write your own android main interface

As we all know, the main interface android named laucher2, powerful android will run after the start, the program is also an entry for all other applications. So, how to make their own applications to replace the position of laucher2 become the main interface android system? In fact, he says it is very simple, then, I come to you to uncover the mystery of this one.

First, let's look at a common declaration of intent application:


<Intent-filter>  
             <Action Android: name = "android.intent.action.MAIN" />  
             <category Android: name = "android.intent.category.LAUNCHER" />  
         </ filter-Intent>  
is not looking very familiar? Yes, and this code is appropriate intent of the statement in AndroidManifest.xml activity, we believe the intent statement currently abbreviation of applications, without exception, it is like it. Many people may have looked in the following two lines of code have appreciated:
the second row <action android: name = "android.intent.action.MAIN " /> indicates that this activity is the main activity of the current application, while the second row represents the current activity in lancher loaded.

So understanding it is true, but in fact, there are more simple to understand manner. Here allow me to secrecy. Let's continue reading.

Since it is to make our own applications to replace laucher position, then we will look at the intent of the statement lancher is kind of how it:


<Intent-filter>  
        <Action Android: name = "android.intent.action.MAIN" />  
        <category Android: name = "android.intent.category.HOME" />  
        <category Android: name = "android.intent. category.DEFAULT "/>  
        <category Android: name =" android.intent.category.MONKEY "/>  
    </ the Intent-filter> 
, of course, want to see this code, you must have the source code laucher. (Questions about android source code, previous articles have mentioned many times, the source code is really a good thing, regardless of the application developers or developers also to the underlying or for android lovers will benefit, so here again we suggest that you do not just limited to the android sdk and avd use to develop applications, whether you have time, if the composition of the source code is always no harm .)
We see the difference between these two declarations of intent yet? Yes, when there is <category android: name = "android.intent.category.HOME" /> when our application will become with lancher have the same function (of course, I mean just the main interface, laucher function is too strong), has become the main interface of the android system, and when we press the Home key, there will be a selection interface that is not found in your application and laucher also appear in a selection box in it? If yes, then congratulations, from a functional point, you have achieved. If not, please email me [email protected].

However, the so-called mountain can not be two tigers, while there are two main interface is certainly not what we want.

If you have android source code, you can even laucher deleted, directly to compile your own applications to android system, so that the system will run when you start the application directly, and your application will will openly dove over the magpie nest, logical system becomes the main interface, and when you press the home key, it will jump to the main activity of your application! !

If you just suitors on a function, then see where you can turn off this page to try the above function.

If you are a strong curiosity of people, then please follow me to continue to look down.

I have just said, understand the problem statement of intent. In fact, you can have a better understanding of the way, of course, to be built on the basis of you have some knowledge of the boot process on the android system.

In simple terms, intent is actually a condition filter, intent statement of activity of each can be used as a filter, the more entries, the filter conditions, the stronger, the more easily locate them. I believe this principle learned friend of the database easier to understand. You can be the entire android system activity are all together as a database, and the intent is itself a select statement, each of which is a filter condition statement, and after filtration and the rest is going to be called activity. When the filter condition or filter powerful enough special conditions, when the last remaining only one activity, then the system will not hesitate to start it; when the conditions that lead to inadequate filtration filter left more of the activity, the system will All activity will meet these criteria are listed with a listview to make your choice.

I believe the principles we have been very clear, so the above this feature well understood. Yes, android at startup will have a choice PackageManager filter system conditions are met:


<Action Android: name = "android.intent.action.MAIN" />  
        <category Android: name = "android.intent.category.HOME" />  
        <category Android: name = "android.intent.category.DEFAULT" / >  
        <category Android: name = "android.intent.category.MONKEY" />  
the activity as a system startup first activity, i.e. the main interface, any activity satisfy this condition the filter will enter the candidate list, if the candidate list only one person, then it is an honor, not to win, you are the system's main interface; if the list of candidates in more than one person (such as just said there laucher and your own application), then enter the brutal "public elections", that is, the user's own choice, the system will start finding out who you are. However, public opinion and election is different, the results are usually elected will have a certain term, and this term election the main interface is very short, whenever you press the Home key once or restart the system, the system will re-arrange a " election public opinion. " If you want to always be the main interface, then the only way is - yes, though very cruel, but have to say - that is, get rid of it ...... or harmony that you can keep it alive, but it must also be relegated to the common people or be exiled frontier specific embodiment means that - to get rid of its intent statement, it does not satisfy the filter criteria of the main interface.
Throughout the intent magical chapters, this chapter is a relatively unique, because while all the chapters using the basic principles of the same, that is, when it comes to the principles I mentioned above, but the intent filter condition in the following chapters can all be defined by the user, manually modify, and only this alone can not be changed, you can decide to adapt or do not fit the filter criteria, but not to change the filter criteria, just as you can to adapt to the society, it is difficult to change it - perhaps not impossible, but temporarily'll find ways ......

Sometimes really, life with computers, actually there are so many similarities ......
----------------
Disclaimer: This article is CSDN blogger "Seven Nights _ snow "in the original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
Original link: https: //blog.csdn.net/louiswangbing/article/details/6607612

Published 36 original articles · won praise 162 · views 620 000 +

Guess you like

Origin blog.csdn.net/qq_19004627/article/details/103911491