If the class activity you mentioned holds an instance, then you can directly pass the instance of the view to it for operation. However, you will usually write a method in the activity to operate the view, and then let other classes call this method, because the instance of the view The creation and destruction are related to the life cycle of the activity, so it is best not to let classes outside the activity directly hold and operate the views in this activity. In addition, be careful to operate the views on the UI thread
Non-activity? Is it a fragment? service? Or what? No matter where you update, it's a communication issue between them. Recommendations: 1. You can use interfaces for communication 2. You can use the EventBar event bus open source library, so that you can learn the use of an open source library
You are talking about operating View in a non-Activity class. Currently, most of them adopt the MVP development model and use the interface callback mechanism to operate View. However, MVP has pros and cons. When operating View, MVP must ensure the persistence of View. deal with.
First of all, you need to know the relationship between your class and this activity. If it is a helper class, then this activity should have an instance of this class. Then you only need to call a corresponding method of this instance. If this class needs To operate a view object or other object in the activity, pass the object as a parameter into the method. If it is other classes, such as service or broadcast, just learn how to use these components I hope it will be helpful to you,,
If the class activity you mentioned holds an instance, then you can directly pass the instance of the view to it for operation. However, you will usually write a method in the activity to operate the view, and then let other classes call this method, because the instance of the view The creation and destruction are related to the life cycle of the activity, so it is best not to let classes outside the activity directly hold and operate the views in this activity. In addition, be careful to operate the views on the UI thread
Non-activity? Is it a fragment? service? Or what? No matter where you update, it's a communication issue between them.
Recommendations:
1. You can use interfaces for communication
2. You can use the EventBar event bus open source library, so that you can learn the use of an open source library
You are talking about operating View in a non-Activity class. Currently, most of them adopt the MVP development model and use the interface callback mechanism to operate View. However, MVP has pros and cons. When operating View, MVP must ensure the persistence of View. deal with.
First of all, you need to know the relationship between your class and this activity. If it is a helper class, then this activity should have an instance of this class. Then you only need to call a corresponding method of this instance. If this class needs To operate a view object or other object in the activity, pass the object as a parameter into the method.
If it is other classes, such as service or broadcast, just learn how to use these components
I hope it will be helpful to you,,