Skip to content

Commit

Permalink
Dropping view moved from onDestroy to onPause
Browse files Browse the repository at this point in the history
  • Loading branch information
Konstantin Mikheev committed Jul 5, 2016
1 parent 7f41b8f commit 9c0e10c
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 10 deletions.
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Wed Apr 10 15:27:10 PDT 2013
#Tue Jul 05 22:25:10 CEST 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.2-all.zip
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,15 @@ protected void onResume() {
presenterDelegate.onResume(this);
}

@Override
protected void onPause() {
super.onPause();
presenterDelegate.onDropView();
}

@Override
protected void onDestroy() {
super.onDestroy();
presenterDelegate.onDropView();
presenterDelegate.onDestroy(!isChangingConfigurations());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ public void onResume() {
}

@Override
public void onDestroyView() {
super.onDestroyView();
public void onPause() {
super.onPause();
presenterDelegate.onDropView();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,15 @@ protected void onResume() {
presenterDelegate.onResume(this);
}

@Override
protected void onPause() {
super.onPause();
presenterDelegate.onDropView();
}

@Override
protected void onDestroy() {
super.onDestroy();
presenterDelegate.onDropView();
presenterDelegate.onDestroy(!isChangingConfigurations());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,15 @@ protected void onResume() {
presenterDelegate.onResume(this);
}

@Override
protected void onPause() {
super.onPause();
presenterDelegate.onDropView();
}

@Override
protected void onDestroy() {
super.onDestroy();
presenterDelegate.onDropView();
presenterDelegate.onDestroy(!isChangingConfigurations());
}
}
7 changes: 6 additions & 1 deletion nucleus/src/main/java/nucleus/view/NucleusActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,15 @@ protected void onResume() {
presenterDelegate.onResume(this);
}

@Override
protected void onPause() {
super.onPause();
presenterDelegate.onDropView();
}

@Override
protected void onDestroy() {
super.onDestroy();
presenterDelegate.onDropView();
presenterDelegate.onDestroy(!isChangingConfigurations());
}
}
4 changes: 2 additions & 2 deletions nucleus/src/main/java/nucleus/view/NucleusFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ public void onResume() {
}

@Override
public void onDestroyView() {
super.onDestroyView();
public void onPause() {
super.onPause();
presenterDelegate.onDropView();
}

Expand Down
3 changes: 3 additions & 0 deletions nucleus/src/test/java/nucleus/view/NucleusActivityTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,13 @@ public void testLifecycle() throws Exception {
tested.onCreate(null);
tested.onResume();
verify(mockDelegate, times(1)).onResume(tested);
tested.onPause();
tested.onDestroy();
verify(mockDelegate, times(1)).onDropView();
verify(mockDelegate, times(1)).onDestroy(false);
tested.onSaveInstanceState(BundleMock.mock());
verify(mockDelegate, times(1)).onSaveInstanceState();
tested.onPause();
tested.onDestroy();
verify(mockDelegate, times(2)).onDropView();
verify(mockDelegate, times(2)).onDestroy(false);
Expand All @@ -135,6 +137,7 @@ public void testSaveRestore() throws Exception {
public void testDestroy() throws Exception {
tested.onCreate(null);
setUpIsFinishing(true);
tested.onPause();
tested.onDestroy();
verify(mockDelegate, times(1)).onDropView();
verify(mockDelegate, times(1)).onDestroy(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ public void testLifecycle() throws Exception {
tested.onCreate(null);
tested.onResume();
verify(mockDelegate, times(1)).onResume(tested);
tested.onPause();
tested.onDestroyView();
verify(mockDelegate, times(1)).onDropView();
tested.onSaveInstanceState(BundleMock.mock());
Expand Down

4 comments on commit 9c0e10c

@vimaxwell
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why don't you presenterDelegate.onDropView() in onStop instead? Because View is actually drop after onStop.

@konmik
Copy link
Owner

@konmik konmik commented on 9c0e10c Jul 12, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

onStart is called before activity state restoration.

This can lead to some data loss when you need to return it from presenter and then state restored and wipes fresh data.

onStop is also not guaranteed, AFAIK.

@vimaxwell
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your reply.
I agree with you. It works almost cases.
But how about this case:
first activity starts a blur activity, so 1st activity goes onPause, not onStop. But we still want to update 1st activity's UI. How can we do it?
https://developer.android.com/training/basics/activity-lifecycle/pausing.html

@konmik
Copy link
Owner

@konmik konmik commented on 9c0e10c Jul 15, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did we already get a real-time blurring algorithm? :)

I think it is safe to stick with the classical onPause way. It was quire reliable, I never had any complains about it. Official Android docs also recommend to pause ongoing actions and unsubscribe from messages.

If you need a special lifecycle, you could use NucleusView which does not depend on onPause/Stop logic at all. Or just create your own view, this is very simple, just copy-paste it and change whatever you need!

Please sign in to comment.