Skip to content

Instantly share code, notes, and snippets.

@twiceyuan
Last active August 16, 2016 00:00
Show Gist options
  • Save twiceyuan/25fa82acdeffd78e345bee562ccefb5b to your computer and use it in GitHub Desktop.
Save twiceyuan/25fa82acdeffd78e345bee562ccefb5b to your computer and use it in GitHub Desktop.
获取全局唯一的整形常量,可以用于 requestCode 的定义,防止其在不同文件中定义时值的碰撞。
public class RequestCode {
private static final AtomicInteger seed = new AtomicInteger();
public static int get() {
return seed.incrementAndGet();
}
}
private static final int REQUEST_CODE = RequestCode.get();
public void doSomething() {
startActivityForResult(intentA, REQUEST_CODE);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment