0

I follow MVP pattern. I have two methods in the presenter setView(Avtivity a) & clearView()

What is better for performance, to call those on onStart() & onStop() or onCreate() & onDestroy

Kordova
  • 73
  • 6

3 Answers3

0

What do you mean? i use MVP and each View have presenter that have a presenter interface with attachView and detachView

And i always call them on onCreate()

I think you should look at the first answer of this post Difference between onCreate() and onStart()?

i think onCreate() is what you should always use if you are attaching a view

Community
  • 1
  • 1
Diogo Rosa
  • 756
  • 1
  • 5
  • 24
0

I would suggest to set Activity View onCreate, and remove it onDestroy, you can also set Fragment View onAttach and remove it onDetach.

I have to add that this is not a concept of performance! You have to avoid memory leak in this regard.

Mohsen Mirhoseini
  • 8,454
  • 5
  • 34
  • 59
0

It depends.. There are 3 sets of callbacks you can use

1) onResume() onPause() Which will make the view reference available to your presenter only when that view is visible and user can interact with it

2) onStart() onStop() Which will make the view reference available to your presenter as above plus if the view is even partially visible

3) onCreate() onDestroy() Which will make the view reference available to your presenter as long as it exists basically

  • So depends on your use case, do you need to update the view, or do anything if the view is not visible? or intractable?
  • Another factor to consider is frequency of calling, because the onCreate() onDestroy() pair will be called only once for each view, while on the other hand the other ones will be called more frequently
elmorabea
  • 3,243
  • 1
  • 14
  • 20