Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
public class MyActivity extends AppCompatActivity implements MyViewInterface {
private MyPresenter presenter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my);
presenter = new MyPresenter(DataManager.getDataManager());
}
@Override
protected void onStart() {
super.onStart();
// instantiates views and sets on click on them.
initView();
}
@Override
protected void onPause() {
// Detach the view as UI isn't going to be visible
presenter.detachView();
super.onPause();
}
@Override
protected void onResume() {
super.onResume();
// Attach the view interface as we want UI updated again.
presenter.attachView(this);
}
private void initView() {
// initialize views and set on click and other stuff here
/* the following line isn't syntactically correct but I
just want to give an idea */
submitButton.setOnClickListener(presenter.saveName(name));
}
@Override
public void updateUI(MyState state) {
/* Update the UI using the MyState object*/
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment