android basic knowledge points

1:
private static CrimeLab sCrimeLab;
android naming convention: you can know that sCrimeLab is a static variable by seeing the s prefix.
2:
What does it mean to add m in front of the variable in java code in Android, and what does it mean to add a?
m means member, that is, a member of the class, a means attribute, means parameter
3:
like R.id.qustion, they are all int types, not String types, that is, resource ids are all int types (may be in r. In the java file, the ID is related to the int type)
4: Press and hold the ctrl key, and the mouse clicks on the method or variable, which will be displayed under this file, and the source code of the method and the explanation of the function will be displayed, just like the official document.
5: There is a difference between android.R.layout and R.layout. android.R.layout is the layout file that comes with the Android SDK. R.layout is the layout you wrote under the res directory.
6: In the java world, to save objects, Either put it in Boundle, or implement Serializable interface or parcelable interface.
7; <item name="#1">#2</item> 1. The name attribute #1 of item can be the attribute of all components brought by the system, and #2 is the value of this attribute
8: android:textStyle = "bold " //set font to bold
9: ObjectInputStream deserializes primitive data and objects previously written using ObjectOutputStream. Only objects that support the java.io.Serializable or java.io.Externalizable interfaces can be read from the stream.
 FileInputStream fis = new FileInputStream("t.tmp");
        ObjectInputStream ois = new ObjectInputStream(fis);


        int i = ois.readInt();
        String today = (String) ois.readObject();
        Date date = (Date) ois .readObject();


        ois.close();
10:
//Get the IP address
System.out.println(addr.getHostAddress());
//Get the name of the machine/or the domain name of the server
System.out.println(addr .getHostName());
11:
There are two kinds of android projects exported by eclipse, one is for eclipse and the other is for androidstudio. The difference between the two is that there is a build folder and a build.gradle file in the root directory, and some are androidstudio projects. , what is not is the eclipse project. "Eclipse projects" cannot be imported into androidstudio. Because there are no two files.
12: Solve the problem of android studio compilation version:
Overwrite the build file and build.gradle file under your own project with these two files in the imported project
13: If the supported library version of the referenced third-party library is lower (or inconsistent) ) version of the support libraries in app build.gradle, the following issue may occur:


all com.android.support libraries must use the exact same version specification(mixing versions can lead to runtime crashes) as shown in the


picture below:


Screenshot 2017-09 -10 12.58.38.png It


is troublesome to change the version of the support library used by the third-party library. If there are many libraries used, the workload will be very large. At this time, we can consider forcing all modules to use the same support library version.


In app build.gradle add:


configurations.all {
    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
        def requested = details.requested
        if (requested.group == 'com.android.support') {
            if (!requested.name.startsWith("multidex")) {
                details.useVersion '25.2.0'
            }
        }
    }
}
where , 25.2.0 is the version number of the support library you want to use, you can change it to other ones as needed.
14: When an error occurs in the design under the xml in androidstudio (there is no error in the text), it is very strange, click the refresh below, and the error disappears.
15: The use of the foreach loop
for(String str:list){
System.out.println(str);
}
14:
The Bundle class is used to carry data, which is similar to Map and is used to store values ​​in the form of key-value name-value pairs .
15:
Understanding of Context It can be said that Context provides an application operating environment. Only in the context of Context can applications access resources and complete interactions with other components or services.
getActivity: The role is to get the activity hosted by the current fragment
16: <string name="subtitle_format">%1$s crimes</string>
What does %1$s mean?

Integer, such as "I am 23 years old", this 23 is an integer. This can be written in string.xml, <string name="old">I am %1$d this year</string> 

17:

After entering this Dongdong, you will enter the following page


By modifying this, you can directly modify the build.gradle file.

18

what is gradle? Gradle is a project construction tool. There are two well-known projects in java development, Maven and Ant. Among them, maven is simple and easy to control and is deeply loved by developers.  

  

The outermost build.gradle file is in the project file, and the second build.gradle file is in the app directory (a project can have multiple moudles, which means there can be multiple apps) build.gradle(Module: app)

19

intent i = new Intent(Intent.ACTION_MAIN);

i.addCategory(Intent.CATEGORY_LAUNCHER);

PackageManager pm = getActivity().getPackageManager();//Use packageManager to get all the main activities that can be started.

List<ResolveInfo> activities = pm.queryIntentActivities(i,0);

Log.i(TAG,"Found"+activities.size()+"activities");

Why can't the following commonly used methods be used?

intent i = new Intent(Intent.ACTION_SEND);

i.addCategory(Intent.CATEGORY_LAUNCHER);

i = Intent.createChooser(i,getString(R.string.send_report));

startActivity (i);


The reason is simple: when the startActivity(); method is called, the operating system silently adds the Intent.CATEGORY_DEFAULT category to the target intent filter. And we only want to get the activities whose category is CATEGORY_LAUNCHER, then those activities with CATEGORY_LAUNCHER but no CATEGORY_DEFAULT cannot be displayed, which is obviously an error.

20

The Java Virtual Machine is a virtual machine process that can execute Java bytecode . Java source files are compiled into bytecode files that can be executed by the Java virtual machine.

The cross-platform of java is not the cross-platform of the java source program. If so, then all languages ​​are cross-platform. The java source program is first compiled into a binary .class bytecode file by the javac compiler (the cross-platform of java refers to It is the cross-platform of .class bytecode files, .class bytecode files are platform-independent), and the .class file runs on the jvm, and the java interpreter (part of the jvm) will interpret it as the machine of the corresponding platform Code execution, so the so-called cross-platform of java is that different JVMs are installed on different platforms, and the .class files generated on different platforms are the same, and the .class files are then interpreted by the JVM of the corresponding platform into the corresponding platform. Machine code execution.

Finally, explain the difference between machine code and bytecode: 1. Machine code, which is completely dependent on hardware ~ and different hardware due to different embedded instruction sets, even the same 0 1 code may mean different ~ In other words, There is no cross-platform at all ~ for example ~ different models of CPU, you give him a command 10001101, they may resolve to different results ~ Second, we know that JAVA is cross-platform, why? Because he has a jvm, no matter what kind of hardware, as long as you have a jvm installed, then he will know the JAVA bytecode~~~ As for the underlying machine code, we don't care, if the jvm is done, he will put the bytecode Then translate it into the machine code recognized by the machine where you are located~~~


21

The java virtual machine is a virtual machine process that can execute java bytecode

A virtual machine is an abstract computer that is implemented by simulating various computer functions on an actual computer. The Java virtual machine has its own complete hardware architecture, such as processor , stack , registers , etc., and also has a corresponding instruction system. The JVM shields the information related to the specific operating system platform, so that the Java program only needs to generate the object code ( bytecode ) running on the Java virtual machine , and it can run on various platforms without modification.

Let's try to understand virtual machines from an operating system level. We know that virtual machines run in the operating system, so what can run in the operating system? Of course it's a process, because a process is a unit of execution in an operating system. It can be understood in this way that when it is running, it is a process instance in the operating system, and when it is not running (stored in the file system as an executable file), it can be called a program.

Finally make a summary:

1 A virtual machine is not mysterious, it is just an ordinary process from the point of view of the operating system.

2 This process called the virtual machine is special, it can load the class file we wrote. If the JVM is compared to a person, then the class file is the food we eat.

3 The class file is loaded by a subsystem called the class loader. Just like our mouths, we eat food into our stomachs.

4 The execution engine in the virtual machine is used to execute the bytecode instructions in the class file. Just like our stomach, it digests the food we eat.

5 During the execution of the virtual machine, it needs to allocate memory to create objects. When these objects become obsolete and useless, these useless objects must be cleaned up automatically. The task of cleaning up objects to reclaim memory is the responsibility of the garbage collector. Just like the food that people eat, after being digested, the waste must be excreted out of the body, making room for eating and digesting the food the next time you are hungry.

22: Serialization problem URL: http://blog.csdn.net/zcl_love_wx/article/details/52126876 (the following is just a part)

All distributed applications often need to be cross-platform and cross-network, so all passed parameters and return values ​​must be serialized.

1. Definition

  Serialization : The process of converting a Java object into a sequence of bytes. 
   
  Deserialization : The process of restoring a sequence of bytes into a Java object.

2. Use

  对象的序列化主要有两种用途: 
   
  1) 把对象的字节序列永久地保存到硬盘上,通常存放在一个文件中;(持久化对象) 
   
  2) 在网络上传送对象的字节序列。(网络传输对象)

三、实现

  实现了如下两个接口之一的类的对象才能被序列化: 
   
  1) Serializable 
   
  2) Externalizable

  序列化:ObjectOutputStream代表对象输出流,它的writeObject(Object obj)方法可对参数指定的obj对象进行序列化,把得到的字节序列写到一个目标输出流中。

  反序化:ObjectInputStream代表对象输入流,它的readObject()方法从一个源输入流中读取字节序列,再把它们反序列化为一个对象,并将其返回。

  注:使用writeObject() 和readObject()方法的对象必须已经被序列化

四、深入理解

一、为什么要序列化?

  Java平台允许我们在内存中创建可复用的Java对象,但只有当JVM(Java虚拟机)处于运行时,这些对象才可能存在,也就是这些对象的生命周期不会比JVM的生命周期更长。但在现实应用中,就可能要求在JVM停止运行之后能够保存指定的对象(持久化对象),并在将来重新读取被保存的对象。Java对象序列化就实现了该功能。 
   
  网络通信时,无论是何种类型的数据,都会转成字节序列的形式在网络上传送。发送方需要把这个Java对象转换为字节序列,才能在网络上传送;接收方则需要把字节序列再恢复为Java对象。Java对象序列化也实现了该功能。

  所以序列化机制会把内存中的Java对象转换成与平台无关的二进制流,从而永久地保存在磁盘上或是通过网络传输到另一个网络节点。


1 ,MVC设计模式中,M指模型层,V指视图层,C指控制层

2,将一个Activity设置成窗口的样式,只需设置Theme

  1. <style name= "Theme.FloatActivity"  parent= "android:style/Theme.Dialog" >  
  2.     <!-- float_box为我们定义的窗口背景 ,这个不是必须的-->  
  3.     <item name="android:windowBackground" > @drawable /float_box</item>  

  1. </style>  

还要在androidManifest.xml文件中加入以下说明

  1. android:theme= "@style/Theme.FloatActivity"   


3  android进程重要性依次是:前台进程、可见进程、服务进程、后台进程、空进程。所以销毁的顺序为逆方向。

4:

  1. 前台进程

    用户当前操作所必需的进程。如果一个进程满足以下任一条件,即视为前台进程:

    通常,在任意给定时间前台进程都为数不多。只有在内存不足以支持它们同时继续运行这一万不得已的情况下,系统才会终止它们。 此时,设备往往已达到内存分页状态,因此需要终止一些前台进程来确保用户界面正常响应。

  2. 可见进程

    没有任何前台组件、但仍会影响用户在屏幕上所见内容的进程。 如果一个进程满足以下任一条件,即视为可见进程:

    • 托管不在前台、但仍对用户可见的 Activity(已调用其 onPause() 方法)。例如,如果前台 Activity 启动了一个对话框,允许在其后显示上一 Activity,则有可能会发生这种情况。
    • 托管绑定到可见(或前台)Activity 的 Service

    可见进程被视为是极其重要的进程,除非为了维持所有前台进程同时运行而必须终止,否则系统不会终止这些进程。

  3. 服务进程

    正在运行已使用 startService() 方法启动的服务且不属于上述两个更高类别进程的进程。尽管服务进程与用户所见内容没有直接关联,但是它们通常在执行一些用户关心的操作(例如,在后台播放音乐或从网络下载数据)。因此,除非内存不足以维持所有前台进程和可见进程同时运行,否则系统会让服务进程保持运行状态。

  4. 后台进程

    包含目前对用户不可见的 Activity 的进程(已调用 Activity 的 onStop() 方法)。这些进程对用户体验没有直接影响,系统可能随时终止它们,以回收内存供前台进程、可见进程或服务进程使用。 通常会有很多后台进程在运行,因此它们会保存在 LRU (最近最少使用)列表中,以确保包含用户最近查看的 Activity 的进程最后一个被终止。如果某个 Activity 正确实现了生命周期方法,并保存了其当前状态,则终止其进程不会对用户体验产生明显影响,因为当用户导航回该 Activity 时,Activity 会恢复其所有可见状态。 有关保存和恢复状态的信息,请参阅 Activity文档。

  5. 空进程

    不含任何活动应用组件的进程。保留这种进程的的唯一目的是用作缓存,以缩短下次在其中运行组件所需的启动时间。 为使总体系统资源在进程缓存和底层内核缓存之间保持平衡,系统往往会终止这些进程。


5:


链接:https://www.nowcoder.com/questionTerminal/86069dcedf8344e19be6a3c54550b36e
来源:牛客网

下列哪些情况下系统会程序抛出异常,强制退出

  • 应用运行时,Main线程进行了耗时操作
  • 应用运行时抛出了OutOfMemoryError
  • 应用运行时抛出了RuntimeException
  • 应用运行时,用户操作过于频繁
AD:产生ANR(application not response),程序没有响应,有可能程序会再次响应
BC:程序抛出异常,会强制退出

FC(Force close)

    原因:

         1.Error

         OOM(out of memory error)

         StackOverFlowError

         2.RuntimeException

6:AIDL:android interface difine language(android自定义接口语言) 


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325680739&siteId=291194637