Demos is based on android 2.3.3 API.
Let's take a look at the ApiDemosApplication. java class, which inherits from the Application and stores some global states. This class will be instantiated when your Application is created,
The class name is the name of the <application> tag of AndroidManifest. xml. For example, in onCreate () in this class:
PreferenceManager. setdefavaluvalues (this, R. xml. default_values, false); this method will fill in the default value from default_values.xml to com. example. android. apis_preferences.xml is included in the default configuration file.
The configuration file is in/data/com. example. android. apis/shared_prefs. According to the official API, This shoshould be called by the application's main activity.
In this way, other activities and services can use the configuration file accordingly.
Next, let's take a look at ApiDemos. java. This class fully applies the AndroidManifest. xml file. First, this class is the program entry, a ListActivity, which will be reused.
In its onCreate () method, the first time path = "" that is, prefix = "", and then look at the getData () method, this method is to fill in the value for this listview, put the entered values in the myData List <Map>:
Intent mainIntent = new Intent (Intent. ACTION_MAIN, null );
MainIntent. addCategory (Intent. CATEGORY_SAMPLE_CODE );
PackageManager pm = getPackageManager ();
List <ResolveInfo> list = pm. queryIntentActivities (mainIntent, 0 );
This code Retrieves all Intent actions in the AndroidManifest. xml file that are ACTION_MAIN and CATEGORY_SAMPLE_CODE. In the list.
The following are some logics that can be understood.
ResolveInfo info = list. get (I );
CharSequence labelSeq = info. loadLabel (pm); obtain the label of all activities. The label format is similar to App/activity/Hello World. If we click App or Activity, we still call ApiDemos. java class, only the content of listview
It's changing. It's in the browseIntent () method.
Each list item is sorted by the ascii code of the first character. You can see in sDisplayNameComparator that the list item can also be filtered by the character you entered.
Author ZircoN