Home > OS >  What could be causing an ANR on setText on a TextView?
What could be causing an ANR on setText on a TextView?

Time:11-20

Now that Firebase has ANR reports, I'm seeing some ANRs that I never saw on the Play Store Console. I'm struggling to understand what I'm doing wrong on some of those situations, for example, I have this one ANR when calling setText on a TextView. How do I go about figuring out the issue? Is it maybe that that the text is too long or something?

main (runnable): tid=1 systid=22334
       at android.content.ContextWrapper.getBaseContext(ContextWrapper.java:91)
       at androidx.appcompat.view.ContextThemeWrapper.getSystemService(ContextThemeWrapper.java:167)
       at android.view.ContextThemeWrapper.getSystemService(ContextThemeWrapper.java:188)
       at android.app.Activity.getSystemService(Activity.java:6896)
       at android.view.ContextThemeWrapper.getSystemService(ContextThemeWrapper.java:188)
       at android.content.Context.getSystemService(Context.java:3736)
       at android.widget.Editor.getInputMethodManager(Editor.java:1919)
       at android.widget.Editor.extractedTextModeWillBeStarted(Editor.java:2706)
       at android.widget.Editor.refreshTextActionMode(Editor.java:2454)
       at android.widget.TextView.spanChange(TextView.java:11989)
       at android.widget.TextView$ChangeWatcher.onSpanAdded(TextView.java:15285)
       at android.text.SpannableStringBuilder.sendSpanAdded(SpannableStringBuilder.java:1297)
       at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:787)
       at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:686)
       at android.text.Selection.setSelection(Selection.java:96)
       at android.text.Selection.setSelection(Selection.java:78)
       at android.text.Selection.setSelection(Selection.java:153)
       at android.text.method.ArrowKeyMovementMethod.initialize(ArrowKeyMovementMethod.java:325)
       at android.widget.TextView.setText(TextView.java:6933)
       at android.widget.TextView.setText(TextView.java:6761)
       at android.widget.EditText.setText(EditText.java:145)
       at android.widget.TextView.setText(TextView.java:6713)
       at MyActivity.mySetTextMethod(MyActivity.java)

CodePudding user response:

Sometimes it's better you don't as you'll be wasting a lot of time figuring out what excactly is happening on that one device. Sometimes it seems to be a too low display resolution, Sometimes it's just the custom operating system of the device itself. To me, this seems more a problem with the android device, than your app itself.

CodePudding user response:

look at this article. maybe you initialized your TextView with the wrong context: Difference between getContext() , getApplicationContext() , getBaseContext() and "this"

  • Related