Answer the question
In order to leave comments, you need to log in
What are the solutions to not recreate the Model class?
The actual code structure:
Activity:
public class MainActivity extends AppCompatActivity {
private iMainActivityModel iModel;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
iModel = new MainActivityModel(this);
}
}
interface iMainActivityModel {
boolean isFirstStart();
void showSetupFragment();
void showMainFragment();
}
class MainActivityModel implements iMainActivityModel {
private Activity activ;
MainActivityModel(Activity activity){
this.activ = activity;
}
@Override
public boolean isFirstStart() {
return false;
}
@Override
public void showSetupFragment() {
}
@Override
public void showMainFragment() {
}
}
Answer the question
In order to leave comments, you need to log in
What do you want to do and where did you get this approach from?
Do you want to put all the logic in the Model and have it manage the Activity? Then it turns out Presenter from MVP. Read articles on the same hub about MVP.
In order not to manually deal with binding the Activity and the Presenter, you can use the Moxy library . She will take over the lifecycle management of the Presenter. There are excellent articles on Moxy on Habré.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question