Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android MVP WeakRefrence

In mvp we save that reference of an activity in a weak reference. WeakReference<Activity> view = new WeakReference<Activity>(activity); If we lose the reference. can we get it back?

like image 902
Methnani Bilel Avatar asked Sep 08 '15 08:09

Methnani Bilel


1 Answers

If you lose the reference to your Activity it means the activity was garbage collected and it doesn't exist anymore. You can't get back what doesn't exist.

Ex. If this happens because of configuration change it means a new activity was created.

You need a way to attach the newly created view to the same presenter.

If you are looking for libraries to help you, take a look at mosby and nucleus.

like image 167
LordRaydenMK Avatar answered Sep 28 '22 12:09

LordRaydenMK



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!