4

I have an EditText that includes text which needs to be linkified for urls, phones and email. I have the following xml:

   <EditText
        android:id="@+id/notes"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:hint="@string/page.notes.placeholder"
        android:inputType="textMultiLine"
        android:lineSpacingExtra="@dimen/margin_small"
        android:minHeight="@dimen/table_row_height"
        android:paddingLeft="@dimen/margin_normal"
        android:paddingRight="@dimen/margin_normal"
        android:layout_marginTop="@dimen/margin_xsmall"
        android:layout_marginBottom="@dimen/margin_xsmall"
        android:singleLine="false"
        android:autoLink="web|email|phone"
        android:linksClickable="true"
        android:textSize="@dimen/medium_textsize"
        />

The setup in Java is:

  EditText notes = (EditText)findViewById(R.id.notes);
  txtNotes = txtNotes.replace("\n", "<br/>");
  notes.setText(Html.fromHtml(txtNotes));
  notes.setMovementMethod(LinkMovementMethod.getInstance());
  notes.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (MotionEvent.ACTION_UP == event.getAction()) {
                if (!notesInFocus){
                    notesFocus();
                    return false;
                }
            }
            return false;
        }
    });

There seems to be something wrong on older phones (e.g. Samsung Galaxy S3mini) where the app crashes when the EditText is clicked and enters edit mode. It is not consistent but usually crashes with a long click on the text. The following is the stack trace:

12-09 14:03:50.808 3265-3265/com.example.android E/AndroidRuntime: FATAL EXCEPTION: main java.lang.IndexOutOfBoundsException: charAt: -1 < 0 at android.text.SpannableStringBuilder.charAt(SpannableStringBuilder.java:112) at android.text.Selection.setSelection(Selection.java:81) at android.text.Selection.setSelection(Selection.java:115) at android.widget.Editor$InsertionHandleView.updateSelection(Editor.java:3805) at android.widget.Editor$HandleView.positionAtCursorOffset(Editor.java:3523) at android.widget.Editor$HandleView.updatePosition(Editor.java:3550) at android.widget.Editor$PositionListener.onPreDraw(Editor.java:2357) at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:707) at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1944) at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1113) at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4481) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725) at android.view.Choreographer.doCallbacks(Choreographer.java:555) at android.view.Choreographer.doFrame(Choreographer.java:525) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711) at android.os.Handler.handleCallback(Handler.java:615) at android.os.Handler.dispatchMessage(Handler.java:92) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:4867) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1007) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:774) at dalvik.system.NativeStart.main(Native Method) 12-09 14:03:50.878 2019-2045/? E/android.os.Debug: !@Dumpstate > dumpstate -k -t -z -d -o /data/log/dumpstate_app_error 12-09 14:03:50.888 2019-2074/? I/InputReader: Touch event's action is 0x1 (deviceType=0) [pCnt=1, s=]

I have also noticed that I cannot replicate a crash if I remove the Linkify. I guess it is a device issue but I get a lot of Crash reports from users about this. Any ideas?

Edit I want to clarify that from crash reports: this issue is exclusive to Samsung devices (with android 4.1.2, 4.2.2, 4.3. 5.1.1).

checklist
  • 12,340
  • 15
  • 58
  • 102

0 Answers0