square / mortar

A simple library that makes it easy to pair thin views with dedicated controllers, isolated from most of the vagaries of the Activity life cycle.
Apache License 2.0
2.16k stars 155 forks source link

2 fatal problem while using service to register the presenter object #201

Open superme001 opened 7 years ago

superme001 commented 7 years ago

problem path: open an Activity(names A, using mortar MVP), then open Activity(B) form Activity(A), and then open a new Activity(A) from Activity(B) , then click back twice, you will see, the presenter object in Activity(A) does not work, the reason list below:

the presenter object is registered by service in the Activity(A), when opening a new Activity(A),the new presenter object is not registered, the reason is obviously below:

image so, problem 1. when the second HelloView get the presenter object using method getSystemService, the result is the same reference to the first HelloView's presenter, you will know that ,the presenter object that the second Activity(A) referenced has no view been attached. problem 2. do as below: image close the second Activity(A), the HelloView detach from the presenter by method dropview, cause the presenter object is the same reference with the first Helloview's, so when back to the first Activity(A), you will see that the presenter has no view attacted, so it does not work.

superme001 commented 7 years ago

i solve the problem myself, we must make sure that one present object for each activity: code below: image