PhoneNumberFormattingTextWatcher导致ANR

时间:2017-12-27 10:00:31

标签: java android

当app ANR,死循环时出现奇怪的调用堆栈。没有与app本身相关的代码,PhoneNumberFormattingTextWatcher在堆栈中多次调用。有没有人遇到同样的问题?非常感谢提供的建议。 重现步骤:在消息传递应用程序的收件人区域中输入数字。

 at android.os.BinderProxy.transactNative(Native method)
 at android.os.BinderProxy.transact(Binder.java:748)
 at android.view.autofill.IAutoFillManager$Stub$Proxy.updateSession(IAutoFillManager.java:452)
 at android.view.autofill.AutofillManager.updateSessionLocked(AutofillManager.java:879)
  at android.view.autofill.AutofillManager.notifyValueChanged(AutofillManager.java:646)
  - locked <0x07dcd96d> (a java.lang.Object)
  at android.widget.TextView.notifyAutoFillManagerAfterTextChangedIfNeeded(TextView.java:9396)
  at android.widget.TextView.sendAfterTextChanged(TextView.java:9380)
  at android.widget.TextView$ChangeWatcher.afterTextChanged(TextView.java:11917)
  at android.text.SpannableStringBuilder.sendAfterTextChanged(SpannableStringBuilder.java:1266)
  at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:576)
  at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:507)
  at android.telephony.PhoneNumberFormattingTextWatcher.afterTextChanged(PhoneNumberFormattingTextWatcher.java:112)
  - locked <0x0637b466> (a android.telephony.PhoneNumberFormattingTextWatcher)
  at android.widget.TextView.sendAfterTextChanged(TextView.java:9375)
  at android.widget.TextView$ChangeWatcher.afterTextChanged(TextView.java:11917)
  at android.text.SpannableStringBuilder.sendAfterTextChanged(SpannableStringBuilder.java:1266)
  at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:576)
  at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:507)
  at android.telephony.PhoneNumberFormattingTextWatcher.afterTextChanged(PhoneNumberFormattingTextWatcher.java:112)
  - locked <0x03c65f17> (a android.telephony.PhoneNumberFormattingTextWatcher)
  at android.widget.TextView.sendAfterTextChanged(TextView.java:9375)
  at android.widget.TextView$ChangeWatcher.afterTextChanged(TextView.java:11917)
  at android.text.SpannableStringBuilder.sendAfterTextChanged(SpannableStringBuilder.java:1266)
  at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:576)
  at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:507)
  at android.telephony.PhoneNumberFormattingTextWatcher.afterTextChanged(PhoneNumberFormattingTextWatcher.java:112)
  - locked <0x08b9b6c4> (a android.telephony.PhoneNumberFormattingTextWatcher)
  at android.widget.TextView.sendAfterTextChanged(TextView.java:9375)
  at android.widget.TextView$ChangeWatcher.afterTextChanged(TextView.java:11917)
  at android.text.SpannableStringBuilder.sendAfterTextChanged(SpannableStringBuilder.java:1266)
  at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:576)
  at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:507)
  at android.telephony.PhoneNumberFormattingTextWatcher.afterTextChanged(PhoneNumberFormattingTextWatcher.java:112)

1 个答案:

答案 0 :(得分:0)

如果你在主线程上做了大量的操作,如果主线程被阻塞,那么主要叫做ANR。

试试这个会对你有帮助。

Thread t = new Thread(new Runnable() {
             @Override
             public void run() {

                 PhoneNumberFormatter.setPhoneNumberFormattingTextWatcher(thi‌​s, mRecipientsEditor);
             }
         });
        t.start();