問題1:發現在Handler中加類似Log.d(TAG,"create handler 1 "+ this);導致系統不能啟動。
- public class Handler {
- public Handler() {
- if (FIND_POTENTIAL_LEAKS) {
- final Class<? extends Handler> klass = getClass();
- if ((klass.isAnonymousClass() || klass.isMemberClass() || klass.isLocalClass()) &&
- (klass.getModifiers() & Modifier.STATIC) == 0) {
- Log.w(TAG, "The following Handler class should be static or leaks might occur: " +
- klass.getCanonicalName());
- }
- }
-
- mLooper = Looper.myLooper();
- if (mLooper == null) {
- throw new RuntimeException(
- "Can't create handler inside thread that has not called Looper.prepare()");
- }
- mQueue = mLooper.mQueue;
- Log.d(TAG,"create handler 1 "+ this); //本行代碼導致系統不能啟動
- mCallback = null;
- }
-
- @Override
- public String toString() {
- return "Handler (" + getClass().getName() + ") {"
- + Integer.toHexString(System.identityHashCode(this))
- + "}";
- }
Answer:
Unknown
問題2:在Handler.toString中加打印this語句導致不能啟動
- @Override
- public String toString() {
- Log.d(TAG,"this="+this);
- return "Handler (" + getClass().getName() + ") {"
- + Integer.toHexString(System.identityHashCode(this))
- + "}";
- }
Answer:
打印this導致toString被調用,因此會出現循環調用。