Greetings,
I want to update the text in my application from my thread to be displayed in my activity.
The only way i know how to update an activity from a thread class (called in the activity) is by creating a static method that is called from thread like this:
Global.score++; //Global class with a score variable
Start.show(); //Start is the caller class
And executed like this:
tvScore.setText(String.ValueOf(Global.score));
And ofc change the modifier of the tvScore to static
.
The only problem is that this code crashes my app, and i was wondering if there is some other way that i can display the score in my activity when something happens on a thread.
Thanks!
EDIT - LOGCAT SHOW
Not sure that this will help, but here is the logcat
07-21 02:15:10.215: E/AndroidRuntime(27608): FATAL EXCEPTION: Thread-91
07-21 02:15:10.215: E/AndroidRuntime(27608): android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
07-21 02:15:10.215: E/AndroidRuntime(27608): at android.view.ViewRootImpl.checkThread(ViewRootImpl.java:4039)
07-21 02:15:10.215: E/AndroidRuntime(27608): at android.view.ViewRootImpl.requestLayout(ViewRootImpl.java:709)
07-21 02:15:10.215: E/AndroidRuntime(27608): at android.view.View.requestLayout(View.java:12675)
07-21 02:15:10.215: E/AndroidRuntime(27608): at android.view.View.requestLayout(View.java:12675)
07-21 02:15:10.215: E/AndroidRuntime(27608): at android.view.View.requestLayout(View.java:12675)
07-21 02:15:10.215: E/AndroidRuntime(27608): at android.view.View.requestLayout(View.java:12675)
07-21 02:15:10.215: E/AndroidRuntime(27608): at android.view.View.requestLayout(View.java:12675)
07-21 02:15:10.215: E/AndroidRuntime(27608): at android.widget.TextView.checkForRelayout(TextView.java:6773)
07-21 02:15:10.215: E/AndroidRuntime(27608): at android.widget.TextView.setText(TextView.java:3306)
07-21 02:15:10.215: E/AndroidRuntime(27608): at android.widget.TextView.setText(TextView.java:3162)
07-21 02:15:10.215: E/AndroidRuntime(27608): at android.widget.TextView.setText(TextView.java:3137)
07-21 02:15:10.215: E/AndroidRuntime(27608): at com.example.fishtruck.Start.showLives(Start.java:123)