Dowemo
0 0 0 0

Notes on @ reading books

We know that the startup activity is divided into two ways to display calls and implicit calls. The display call needs to explicitly specify the component information for the initiated object, including the package name and the class name, and the implicit call needs intent to match the filtering information set in the target component 's 's intentfilter, which won't start the filter information in the target activity.
- action.
- category
- data.

An example of the filter rule is as follows:

<activityandroid:name="com.simon.activity.SecondActivity"android:launchMode="singleTask"> <intent-filter><actionandroid:name="com.simon.activity1"/><actionandroid:name="com.simon.activity2"/><categoryandroid:name="com.simon.activity3"/><categoryandroid:name="com.simon.activity4"/><categoryandroid:name="android.intent.category.DEFAULT"/><dataandroid:mimeType="text/plain"/></intent-filter></activity>

To match the filter list, match the action, category, data information in the filter list, or match. An action, category, and data in a filter list can have multiple, all action, category, data co & ist of different categories, and information of the same category co & TRAI not the matching process for the current category. Only one intent matches the action category, category category, the data category, and the data category. The target activity can be started successfully only if the match is complete. In another point, there can be multiple intent filters in an activity. An intent can be able to start the corresponding activity as long as any set of intent filters can be matched.

A matching rule for 1. Action:
Action is a string that's ordered by the system, and we can also define its own action in the application. Action matching rule is the action in intent that must be able to match the action in the filter rule, which is exactly the same as the value of the string for the action. A filter rule can have more than one action, so as long as the action in intent can match any action in the filter rule. For the above filtering rules, as long as the action value in our intent is"com. Simon. Activity1"or"com. Simon. Activity2", it can match success. Note that if no action is specified in intent, the match fails.
Summary:
Action matching requires the action in intent and must be the same as one of the filtering rules, where you need to notice that it's different from the category match. In addition, action is case sensitive, different size, the same characters match.

A matching rule for 2. Category:
Category is a string that takes a number of categories, and we can also define your own category. Category matching rules and action in your application. It requires that all categories have the same category as the category, and all categories must be in the same category as the filter rules. In other words, in intent, if category is present, it must be a category that has been defined in the filter rule for each category. Of course, there's no category, and if there's no category, this intent can still match success. It's important to note that the action is the same as the action match process, which requires that an action must be in an intent and must be able to be the same as an action in the filter rule, but the category demands can be in the same way as any one of the categories in the filter rule, regardless of the number of cageroy. In order to match the category in the previous filtering rule, we can add intent to intent. AddCategory ("com. Simon. Activity3") or intent. AddCategory ("com. Simon. Activity4") or doesn't set the category. Why don't you set a category. The reason is that the system defaults to intent plus"android, intent, category, default"category, so this category matches the third category in the previous filter rule. In the meantime, you must specify"android. Intent. Category. Default"in the intent filter for our activity to accept implicit invocation.

A matching rule for 3. Data:
Data matching rules and actions similar to that, if data is defined in the filter rule, then the intent must also define a matching data.

Look at the structure of the data:

 <data 
 android:scheme="string"
 android:host="string"
 android:port="string"
 android:path="string"
 android:pathPattern="string"
 android:pathPrefix="string"
 android:mimeType="string"
/>

Data is composed of two parts, mimetype, and uris. Minetype refers to media types such as image jpeg, audio/mepeg4-generic and video/*. You can represent different media formats such as picture, text, video, and the data contained in the uri. The following is the structure of the uri:

<scheme>://<host>:<port>/[path]|[pathPrefix]|[pathPattern]

Example:

content://com.example.project:200/folder/subfolder/etc
http://www.baidu.com:80/search/info
  • Schema: the schema for the uri, such as http, file, content, and so on, if no scheme is specified in the uri, then the whole uri is invalid. This also means that the uri is invalid.
  • Host: the hostname of the uri, for example www. Baidu. Com, if the host isn't specified, the other argument in the entire uri is invalid, which mea & that the uri is invalid.
  • Port: the port number in the uri, such as 80, is meaningful only if the scheme and host arguments are specified in the uri.

Path, pathPattern, and pathPrefix: All three parameters represent path information where path represents the full path information, but it can contain wildcard"*","*","","","*",""is written as"*", and pathPrefix represents the prefix information of the path; represents the prefix information for the path.

After introducing data format, look at the matching rules of data. Data matching rules, similar to actions, also require that the intent must contain data data, and data data can match exactly one of the data in the filter rule.

As the following filter rules:

<intent-filter><dataandroid:mimeType="image/*"/></intent-filter>

In this rule, the media type is specified for all types of pictures, so the mime attribute in intent must be"image/*"to match, in this case, although the filter rule doesn't specify a uri, the default value of the uri is content and file. That's, although the uri isn't specified, the scheme of the uri part in intent must be content or file.
For example, to match the above rule: We can write the following code:

intent.setDataAndType(Uri.parse("file://abc)"),"image/png");

In addition, if you want to specify the full data for intent, you must call the method and call settype to call.

For example, the following filter rules:

<intent-filter><dataandroid:mimeType="video/mpeg"android:scheme="http"/><dataandroid:mimeType="audio/mpeg"android:scheme="http"/></intent-filter>

This filter specifies two sets of data data, and each data specifies a complete property value, both with a uri and a mime. To match the above rule, we can write the following code to match:

 intent.setDataAndType(Uri.parse("http://abc)"),"video/mpeg");或者 intent.setDataAndType(Uri.parse("http://abc)"),"audio/mpeg");

Here, we write the matching rules of the intentfilter that's simple:
As follows:

 intent.setAction("com.simon.activity1"); intent.addCategory("com.simon.activity3"); intent.setDataAndType(Uri.parse("content://abc)"),"text/plain");

When you start the application implicitly, determine whether there's an activity that matches the application
It's important to note that when we use implicit start activity, we need to determine whether there's an activity that can match, and if it's called directly,!

android.content.ActivityNotFoundException:NoActivity found tohandle Intent

There are two ways to judge:
1. Using the method or intent of packagemanager, if they can't find a matching activity, it returns null, and we can avoid the above error by judging the return value. In addition, packagemanager provides the queryIntentActivities method, which is different from the resolveActivity method: It doesn't return the best matching activity but returns all successful matching activity information. Let's look at the method prototype of queryIntentActivities and resolveActivity:

publicabstract ResolveInfo resolveActivity(Intent intent, @ResolveInfoFlags int flags);publicabstract List<ResolveInfo> queryIntentActivities(Intent intent,
 @ResolveInfoFlags int flags);

The first argument is the intent that needs to be started, and the second argument we need to use the match _ default only to the token bit, the meaning of this flag is

<categoryandroid:name="android.intent.category.DEFAULT"/>

An activity in this category. The meaning of using this flag is that, as long as the two methods don't return null, startactivity must be successful. If you don't use this flag bit, you can also match the category in the intent filter to the activity that doesn't have dedfault, causing startactivity to fail.




Copyright © 2011 Dowemo All rights reserved.    Creative Commons   AboutUs