Android TextView text is showing up as black squares?
Asked Answered
P

3

1

I have a TextView in my application that works fine until I pause the application (by pressing home) and launch it again. It should just resume the activity, but for some reason the TextView doesn't display the text properly after it resumes the activity. The text is showing up as black squares, like this:

https://i.sstatic.net/5mtvy.png

Does anyone know how to fix this?

EDIT: Here's my code: The TextView is created in a layout xml that has a GLSurfaceView (called GameView) and on top of that a TextView. Here's the xml code:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="MainActivity" >

    <GameView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/gv"
        />

    <TextView
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:textColor="@android:color/black"
        android:id="@+id/tv" />

</RelativeLayout>

And here is the code in the MainActivity class onCreate method:

    setContentView(R.layout.activity_main);
    GameView gameView = (GameView) findViewById(R.id.gv);
    TextView textView = (TextView) findViewById(R.id.tv);

The onPause, onResume, onStart, onStop methods have nothing related to the TextView. The TextView is saved into an instance variable for MainActivity and later, TextView.setText() is called to set the text of the TextView.

EDIT: I was able to fix this problem by commenting out one line: GLES20.glDeleteTextures(...) that was being called onPause() I have NO idea how this is even related or why calling this function caused that issue, but when I comment it out the problem goes away and when I bring this line back the problem comes back with it. If anyone can explain how one relates to the other, it would be greatly appreciated.

Pedanticism answered 10/8, 2014 at 0:18 Comment(2)
Looks like this exact same thing happens with a TextView on top of a CrossWalk embedded XWalkView. Sadly the forceLayout() call on resume does not make a difference here.Limann
NOTE: Observed in Android Kitkat 4.4.4 (API 19) only, not in 4.3 or older.Limann
G
0

Check what u have in on start and on stop methods, it is for sure painting what u have typed earlier.

Glop answered 10/8, 2014 at 0:28 Comment(3)
I am not implementing the onStart and onStop methods myself. What do you mean that it is painting what I typed earlier? Do I have to clear it somehow when the activity is resumed?Pedanticism
Actually you dont have to do anything. If you post your oncreate onstart n onresume code n layout may be i can point out what is going wrong.Glop
If you cannot find out what is wrong, can you tell me what can cause this kind of behavior? What did you mean when you said it is painting what I typed earlier?Pedanticism
E
0

Try putting

@Override
public void onResume() {
    super.onResume(); // Always call the superclass method first

TextView textView = (TextView) findViewById(R.id.tv);
textView.forceLayout();

}

Let me know if this solves your problem or not?

Electrolyte answered 10/8, 2014 at 4:13 Comment(1)
I was able to figure out how to fix the problem although I have no idea why my solution worked. I edited my solution into my original post.Pedanticism
S
0

I encountered the same situation.

Just make sure your deleting view(which uses opengl) texture action in the thread you created it.

In your case, GameView is the key.

Superaltar answered 14/11, 2017 at 12:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.