Closed DrewCarlson closed 8 years ago
yes this is correct. Maybe onPostCreate()
is better suited than onResume()
. However, people are used to call presenter methods like presenter.loadData()
in Activity.onCreate()
.
So they would have to move that to onPostCreate()
too. You see, you make the other half of users happy by disapointing the others. Furthermore this is a breaking change.
So what I typically do is something like this:
class MyActivity extends MvpActivity {
public void onCreate(Bundle b) {
setContentView(R.layout.my_layout);
// findViewById() etc.
super.onCreate(b);
}
}
Call super.onCreate()
after having set ContentView.
Alternatively, if you really want to have presenter.attachView()
called in onResume()
you could write your own MvpDelegate that does that in onResume()
. Checkout Mosby's github pages for more information about that.
What do you think?
If this is intended behavior then any of these solutions are fine with me. I have been using your first solution of having an initialization method on the presenter that gets called in onCreate()
.
My issue with that is that it's only required for Activities, which (though small) is a difference I have to keep track of between Fragments and Views.
The second approach you provided seems like the best option for me.
Thank you for your insight.
I may be missing something here but since
onCreate
will instantiate the Presenter and immediately callattachView
, the Activity will not have had the chance to callsetContentView
. This would cause any calls to your MvpView that have afindViewById
to fail when called inattachView
.