Record Android fragmented knowledge points in the project for memo.
1, Android Custom permissions
The app can customize its own permissions:
<android:description= "string resource" android:icon= "drawable Resource " android:label=" string resource " android:name=" string " Android:permissiongroup= "string" android:protectionlevel />
where ProtectionLevel is a permission level:
1, Normal: The default grant permission does not prompt the user;
2. Dangerous: Notify the user when the installation declares such permission;
3, Signature: Only for the use of the same certificate signed app open;
4, Signatureorsystem: On the basis of signature, on the ROM to add their own app statement;
such as: Broadcastreceiver + android:protectionlevel=signature, you can only accept the same signature app sent messages;
2, Android:process
By default, Android creates a process for each app, and all components run under the change process. The process name is the package name, such as com.xx.xx;
application has its own independent memory and resource control, in order to solve the single-process resource constraints, Android provides multi-process in the application, such as in complex drawing, frequent message monitoring and other independent processes. The android:process attribute is used.
<activity>,<service>, <receiver>, and <provider> have this attribute.
android:process = ": Hello"
android:process = ". Hello"
start with ":" to indicate that the process is private; the process is named Com.xx.xx:hello
starts with a lowercase letter, which means that this is a global process that allows other application components to run in this process, with the process named Hello
3. Log Module
Android provides a more mature logging module, but it is also used in commercial software to expand it.
1. Define the log storage file path in the Android external storage;
2, when invoking the Log tool class, except the native log, writes the file;
3. Note that when you write a file, you take care of the thread alone:
private static final Executor logger = Executors.newsinglethreadexecutor ();
Logger.execute (New Runnable (//log file write)}
4. Activity's Android:configuration attribute
When you do not set the activity's android:configchanges, the screen will recall the life cycle, cut across the screen will be executed once, cut the vertical screen will be executed two times 2, set activity android:configchanges= " Orientation ", the screen will still recall the life cycle, cut horizontal, vertical screen will only execute once 3, set activity of android:configchanges=" Orientation|keyboardhidden ", The screen does not recall the individual lifecycles, only the Onconfigurationchanged method is executed
5. Android uses Getdefaultuncaughtexceptionhandler to get global exceptions
Android "program Abnormal Exit", to the user experience to adversely affect, can inherit the Uncaughtexceptionhandler class to handle,
The exception is captured with Thread.setdefaultuncaughtexceptionhandler (). Code examples (in fact, supported after Java 5.0) are as follows:
ImportJava.lang.Thread.UncaughtExceptionHandler; Public classApp { Public Static voidMain (string[] args) {Testthread a=NULL; NewTestthread ("Fredric Test 1"). Start (); NewTestthread ("Fredric Test 2"). Start (); /** Output result this is:fredric test 1,message:/by zero this is:fredric test 2,message:/by Zero*/ }}classcrashhandler{Private StaticCrashhandler instance; PrivateUncaughtexceptionhandler Handler; PrivateCrashhandler () {handler=Thread.getdefaultuncaughtexceptionhandler (); Thread.setdefaultuncaughtexceptionhandler (NewUncaughtexceptionhandler () {@Override Public voiduncaughtexception (Thread T, Throwable e) {System.out.println ("This is:" + t.getname () + ", Message:" +e.getmessage ()); Handler.uncaughtexception (t, e); } }); } Public StaticCrashhandler getinstance () {if(NULL==instance) {Instance=NewCrashhandler (); } returninstance; }}classTestthreadextendsThread { PublicTestthread (String name) { This. SetName (name); //called in the OnCreate of applicationcrashhandler.getinstance (); } Public voidrun () {Doublei = 10/0;//where the exception is thrown }}
Android Knowledge (iii)