Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes asynch launchTwa freezing splash screens #297

Merged
merged 5 commits into from
Jun 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,18 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
return;
}

mMetadata = LauncherActivityMetadata.parse(this);

if (splashScreenNeeded()) {
mSplashScreenStrategy = new PwaWrapperSplashScreenStrategy(this,
mMetadata.splashImageDrawableId,
getColorCompat(mMetadata.splashScreenBackgroundColorId),
getSplashImageScaleType(),
getSplashImageTransformationMatrix(),
mMetadata.splashScreenFadeOutDurationMillis,
mMetadata.fileProviderAuthority);
}

if (shouldLaunchImmediately()) {
launchTwa();
}
Expand All @@ -175,16 +187,12 @@ protected boolean shouldLaunchImmediately() {
* {@link #shouldLaunchImmediately()} returns {@code false}.
*/
protected void launchTwa() {
mMetadata = LauncherActivityMetadata.parse(this);

if (splashScreenNeeded()) {
mSplashScreenStrategy = new PwaWrapperSplashScreenStrategy(this,
mMetadata.splashImageDrawableId,
getColorCompat(mMetadata.splashScreenBackgroundColorId),
getSplashImageScaleType(),
getSplashImageTransformationMatrix(),
mMetadata.splashScreenFadeOutDurationMillis,
mMetadata.fileProviderAuthority);
// When launching asynchronously, developers should check if the Activity is finishing
// before calling launchTwa(). We double check the condition here and prevent the launch
// if that's the case.
if (isFinishing()) {
Log.d(TAG, "Aborting launchTwa() as Activity is finishing");
return;
}

CustomTabColorSchemeParams darkModeColorScheme = new CustomTabColorSchemeParams.Builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ public class FirebaseAnalyticsLauncherActivity extends LauncherActivity {
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

// `super.onCreate()` may have called `finish()`. In this case, we don't do any work.
if (isFinishing()) {
return;
}

FirebaseAnalytics firebaseAnalytics = FirebaseAnalytics.getInstance(this);

// Start the asynchronous task to get the Firebase application instance id.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ public class OfflineFirstTWALauncherActivity extends LauncherActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

// `super.onCreate()` may have called `finish()`. In this case, we don't do any work.
if (isFinishing()) {
return;
}
tryLaunchTwa();
}

Expand Down