If the same part of your code is the interface and the corresponding logic, just use Fragment. Why do you need to pass it? The Context is generally passed only to use the Context method, rather than down-converting to a specific Activity, which is too coupled. If the same part of code is a small piece of code, put the code in a BaseActivity and let other activities inherit it.
1. If it is a public method and the functions implemented are the same: Write a base class of Activity, BaseActivity, and write the public method in the base class for subclasses to call. 2. If the functions implemented by the public methods are different, the method names must be the same. : The same method is to create the base class BaseActivity and write an abstract method. The specific implementation is completed in the subclass PS: Passing context will definitely not get the objects in the Activity. At least you must write ((Activity)context)
1. Abstract the same method into
BaseActivity
.You can write shared code in Activity A, and then the Activity that needs to use the shared code inherits Activity A
You can use Mvp mode to put the same part of the logical control layer into the Present layer for management.
Can you tell me what this method is used for? Because your return is similar to void, you must do something through contxt
If the same part of your code is the interface and the corresponding logic, just use Fragment. Why do you need to pass it? The Context is generally passed only to use the Context method, rather than down-converting to a specific Activity, which is too coupled. If the same part of code is a small piece of code, put the code in a BaseActivity and let other activities inherit it.
You haven’t gotten started with Java yet, lay the foundation first
1. If it is a public method and the functions implemented are the same:
Write a base class of Activity, BaseActivity, and write the public method in the base class for subclasses to call.
2. If the functions implemented by the public methods are different, the method names must be the same. :
The same method is to create the base class BaseActivity and write an abstract method. The specific implementation is completed in the subclass
PS: Passing context will definitely not get the objects in the Activity. At least you must write ((Activity)context)
Write an abstract parent class. Put the shared methods in there.