Post startService() in onPause() as a possible fix to an Android P bug.

We already did it for onResume(), and while it fixed the crash there,
the crash just moved to onPause(). Let's see if the same magic works.
This commit is contained in:
Greyson Parrelli 2018-10-16 22:54:29 -07:00
parent 1a5c1a4b42
commit feb9e1d513
2 changed files with 12 additions and 7 deletions

View File

@ -61,6 +61,7 @@ public abstract class PassphraseRequiredActionBarActivity extends BaseActionBarA
protected void onResume() {
Log.i(TAG, "onResume()");
super.onResume();
isVisible = true;
// Android P has a bug in foreground timings where starting a service in onResume() can still crash
Util.postToMain(() -> {
@ -69,19 +70,19 @@ public abstract class PassphraseRequiredActionBarActivity extends BaseActionBarA
if (!networkAccess.isCensored(this)) MessageRetrievalService.registerActivityStarted(this);
else ApplicationContext.getInstance(this).getJobManager().add(new PushNotificationReceiveJob(this));
});
isVisible = true;
}
@Override
protected void onPause() {
Log.i(TAG, "onPause()");
super.onPause();
KeyCachingService.registerPassphraseActivityStopped(this);
if (!networkAccess.isCensored(this)) MessageRetrievalService.registerActivityStopped(this);
isVisible = false;
// Android P has a bug in foreground timings where starting a service in onPause() can still crash
Util.postToMain(() -> {
KeyCachingService.registerPassphraseActivityStopped(this);
if (!networkAccess.isCensored(this)) MessageRetrievalService.registerActivityStopped(this);
});
}
@Override

View File

@ -115,8 +115,12 @@ public class WebRtcCallActivity extends Activity {
public void onPause() {
Log.i(TAG, "onPause");
super.onPause();
if (!networkAccess.isCensored(this)) MessageRetrievalService.registerActivityStopped(this);
EventBus.getDefault().unregister(this);
// Android P has a bug in foreground timings where starting a service in onPause() can still crash
Util.postToMain(() -> {
if (!networkAccess.isCensored(this)) MessageRetrievalService.registerActivityStopped(this);
});
}
@Override