Question

I have 2 classes - Buttons_Class - Display_Class On the screen I show a few Buttons and a TextView at all times. The Buttons class sends a startActivityforResult to the Display class with a string in a bundle. The Display class manipulates that string and shows something in a TextView. That is working fine. In order to go back to the Buttons class the Display class sends back an Intent with a setResult. This is also working well. But then Display class has to do a finish() and this erases the information in the TextView. How can the information in a TextView be kept while many other activities start and stop?

Was it helpful?

Solution

"I need a global TextView?" - No you don't. Ever. (I know that's a strong word, but really)

A TextView is a user interface element. It should display a graphical representation of external data. You need to decouple the data model from the user interface. This can be done in a number of ways; probably the simplest is to store your data model in a singleton class that is accessible throughout the application. Your Activity classes should simply access the data and provide a visual representation of it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top