1 Functions of four Android components? Activity: interface, display controls, activities communicate with each other through Intent. Service: BroadCastReceiver, used for background services, can be used to develop a monitoring class of programs: Your application can use it to filter for external events, to receive and respond to specific external events (when a phone is connected or a data network is available). It doesn’t have an interface, but it can launch an Actvity or Service in response to the information it receives. ContentProvider: Used to share data between applications, which can be stored in a file system or SQLite database. 2 non-resident broadcast: life cycle with the Activity, register in a manifest file, BroadcastReceiver, inherit BroadcastReceiver, override onReceive() to receive broadcast messages,
Resident broadcast: when the application is closed, if there is a broadcast, the program will also be called by the system to receive the broadcast; Dynamic registration using code: IntentFilter (BroadcastReceiver, IntentFilter); SmsBroadCastReceiver = new smsBroadCastReceiver (); // Instantiate the filter and set the broadcasts to filter
IntentFilter IntentFilter = new IntentFilter (” android. The provider. A Telephony. SMS_RECEIVED “);
/ / registered radio BroadCastReceiverActivity. This. RegisterReceiver (smsBroadCastReceiver intentFilter);
3 What is the difference between the Asset folder and the raw folder on Android?Copy the code
Similarities: Files in both directories will be stored intact in apK package after packaging, and will not be compiled into binary files. The file in RES/RAW is mapped to the r.java file. The resource ID is r.raw.filename when the file is accessed. Res/RAW cannot have a directory interface. Assets can have a directory structure under which files can be accessed from folders. InputStream in = getResources(). OpenRawResouces (r.raw.filename) Through the Assetmanager class Assetmanager am = getAssets(); InputStream is = am. Open (” filename “);
4 Five Storage modes in Android:Copy the code
(1) SharePreferences storage paths (data/data/packageName/shares_prefes) lightweight storage, key/value pairs stored in XML, general information is used to store application Settings. (2) File storage SD card storage multi-media, file cache. (3) the SQLite database storage paths (data/data/packageName/databases), a kind of embedded database, support SQL, a large number of structured data storage. (4) Data sharing between ContentProvider processes (applications), data sources: SQLite database, XML stakeholders ContentResolver (content parser), ContentObserver (data observer). (5) Network storage, XML, JSON format data through HttpUrlConnection, HttpClient or SOAP protocol read data