Android代码中遇到的一些警告或问题汇总

来源:互联网 发布:日本ip代理地址和端口 编辑:程序博客网 时间:2024/06/01 18:55

1、‘catch’branch identical to‘instantiationexception’branch:
Reports identical catch sections in try blocks under JDK 7. A quickfix is available to collapse the sections into a multi-catch section.
This inspection only reports if the project or module is configured to use a language level of 7.0 or higher.
警告的大体意思是在jdk1.7环境下的try块中捕获到了相同或相似的异常,快速的解决办法是把这些部分折叠起来到一个multi-catch部分中,下面举一个例子:
下面是报警告的部分
这是警告
这是解决后的代码
消除警告后的代码
如果上面描述的不清楚,看图可一目了然。
2、 Avoid object allocations during draw/layout operations (preallocate and reuse instead)
这个问题是说我在onDraw()中创建新对象了,因为onDraw()调用频繁,不断进行创建和垃圾回收会影响性能,下面是StackOverFlaw上描述的解决办法:Better way could be to declare these object at class level and initialize them in constructor, and just make drawXxx() calls in onDraw method.意思是更好的办法是在类这一层级描述对象,然后在构造方法中初始化对象。

原创粉丝点击