Skip to content

Commit

Permalink
Restart activity in onNewIntent if activity is not yet initialized.
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-signal committed Mar 16, 2021
1 parent 490944a commit 0c53590
Showing 1 changed file with 16 additions and 0 deletions.
Expand Up @@ -400,6 +400,8 @@ public class ConversationActivity extends PassphraseRequiredActivity
private boolean isMmsEnabled = true;
private boolean isSecurityInitialized = false;

private volatile boolean screenInitialized = false;

private IdentityRecordList identityRecords = new IdentityRecordList(Collections.emptyList());
private final DynamicTheme dynamicTheme = new DynamicNoActionBarTheme();
private final DynamicLanguage dynamicLanguage = new DynamicLanguage();
Expand Down Expand Up @@ -449,6 +451,11 @@ protected void onCreate(Bundle state, boolean ready) {
initializeSecurity(recipient.get().isRegistered(), isDefaultSms).addListener(new AssertedSuccessListener<Boolean>() {
@Override
public void onSuccess(Boolean result) {
if (isFinishing()) {
Log.w(TAG, "Activity is finishing. Not proceeding with initialization.");
return;
}

initializeProfiles();
initializeGv1Migration();
initializeDraft(args).addListener(new AssertedSuccessListener<Boolean>() {
Expand All @@ -469,6 +476,8 @@ public void onSuccess(Boolean loadedDraft) {
composeText.addTextChangedListener(typingTextWatcher);
}
composeText.setSelection(composeText.length(), composeText.length());

screenInitialized = true;
}
});
}
Expand All @@ -486,6 +495,13 @@ protected void onNewIntent(Intent intent) {
return;
}

if (!screenInitialized) {
Log.w(TAG, "Activity is in the middle of initialization. Restarting.");
finish();
startActivity(intent);
return;
}

reactWithAnyEmojiStartPage = -1;
if (!Util.isEmpty(composeText) || attachmentManager.isAttachmentPresent() || inputPanel.getQuote().isPresent()) {
saveDraft();
Expand Down

0 comments on commit 0c53590

Please sign in to comment.