Android 小手段

查看签名

很多开发者服务都需要绑定签名信息,用下面的命令可以查看签名:


keytool -list -v -keystore release.jks

单例模式(懒汉式)的更好的写法

1.JDK1.5就引入volatile关键字,所以有了一种更好的双重校验锁写法:


public class Singleton {
private volatile static Singleton singleton;
private Singleton (){}
public static Singleton getSingleton() {
if (singleton == null) {
synchronized (Singleton.class) {
if (singleton == null) {
singleton = new Singleton();
}
}
}
return singleton;
}
}
注意,别忘记volatile关键字哦,否则就是10重,100重也可能还是会出问题。
2.另外一种静态内部类写法更推荐:

publlic class Singleton {
private Singleton() {}
private static class SingletonLoader {
private static final Singleton INSTANCE = new Singleton();
}
public static Singleton getInstance() {
return SingletonLoader.INSTANCE;
}
}

ListView的局部刷新

有的列表可能notifyDataSetChanged()代价有点高,最好能局部刷新。局部刷新的重点是,找到要更新的那项的View,然后再根据业务逻辑更新数据即可。


private void updateItem(int index) {
int visiblePosition = listView.getFirstVisiblePosition();
if (index - visiblePosition >= 0) {
//得到要更新的item的view
View view = listView.getChildAt(index - visiblePosition);
// 更新界面(示例参考)
// TextView nameView = ViewLess.$(view, R.id.name);
// nameView.setText("update " + index);
// 更新列表数据(示例参考)
// list.get(index).setName("Update " + index);
}
}

系统内置的一些工具类

// 系统
./android/database/DatabaseUtils.java
./android/transition/TransitionUtils.java
./android/view/animation/AnimationUtils.java
./android/view/ViewAnimationUtils.java
./android/webkit/URLUtil.java
./android/bluetooth/le/BluetoothLeUtils.java
./android/gesture/GestureUtils.java
./android/text/TextUtils.java
./android/text/format/DateUtils.java
./android/os/FileUtils.java
./android/os/CommonTimeUtils.java
./android/net/NetworkUtils.java
./android/util/MathUtils.java
./android/util/TimeUtils.java
./android/util/ExceptionUtils.java
./android/util/DebugUtils.java
./android/drm/DrmUtils.java
./android/media/ThumbnailUtils.java
./android/media/ImageUtils.java
./android/media/Utils.java
./android/opengl/GLUtils.java
./android/opengl/ETC1Util.java
./android/telephony/PhoneNumberUtils.java
// 设计和支持库
./design/src/android/support/design/widget/ViewGroupUtils.java
./design/src/android/support/design/widget/ThemeUtils.java
./design/src/android/support/design/widget/ViewUtils.java
./design/lollipop/android/support/design/widget/ViewUtilsLollipop.java
./design/base/android/support/design/widget/AnimationUtils.java
./design/base/android/support/design/widget/MathUtils.java
./design/honeycomb/android/support/design/widget/ViewGroupUtilsHoneycomb.java
./v7/recyclerview/src/android/support/v7/widget/helper/ItemTouchUIUtil.java
./v7/recyclerview/src/android/support/v7/widget/helper/ItemTouchUIUtilImpl.java
./v7/recyclerview/src/android/support/v7/util/MessageThreadUtil.java
./v7/recyclerview/src/android/support/v7/util/AsyncListUtil.java
./v7/recyclerview/src/android/support/v7/util/ThreadUtil.java
./v7/recyclerview/tests/src/android/support/v7/widget/AsyncListUtilLayoutTest.java
./v7/recyclerview/tests/src/android/support/v7/util/AsyncListUtilTest.java
./v7/recyclerview/tests/src/android/support/v7/util/ThreadUtilTest.java
./v7/appcompat/src/android/support/v7/graphics/drawable/DrawableUtils.java
./v7/appcompat/src/android/support/v7/widget/DrawableUtils.java
./v7/appcompat/src/android/support/v7/widget/ThemeUtils.java
./v7/appcompat/src/android/support/v7/widget/ViewUtils.java
./v4/tests/java/android/support/v4/graphics/ColorUtilsTest.java
./v4/jellybean-mr1/android/support/v4/text/TextUtilsCompatJellybeanMr1.java
./v4/jellybean/android/support/v4/app/BundleUtil.java
./v4/jellybean/android/support/v4/app/NavUtilsJB.java
./v4/java/android/support/v4/app/NavUtils.java
./v4/java/android/support/v4/database/DatabaseUtilsCompat.java
./v4/java/android/support/v4/graphics/ColorUtils.java
./v4/java/android/support/v4/text/TextUtilsCompat.java
./v4/java/android/support/v4/util/TimeUtils.java
./v4/java/android/support/v4/util/DebugUtils.java
./v4/java/android/support/v4/content/res/TypedArrayUtils.java

dpi文件夹的换算比例

之前的ldpi基本可以抛弃了,主流的dpi已经从很早之前的mdip转移到了xhdpi了,特别提醒。
PPI RESOLUTION DP PX
mdpi(160dp) 320P 1 1
hdpi(240dp) 480P 1 1.5
xhdpi(320dp) 720P 1 2
xxhdpi(480dpi) 1080P 1 3

Monkey参数

跑monkey的参数设置有一些要注意的地方,比如太快了不行不切实际,太慢了也不行等等,这里给出一个参考:


adb shell monkey -p -s 1000 --ignore-crashes --ignore-timeouts --ignore-security-exceptions --pct-trackball 0 --pct-nav 0 --pct-majornav 0 --pct-anyevent 0 -v --throttle 300 1200000000

~20160523

你可能感兴趣的:(Android 小手段)