Skip to content

Commit

Permalink
Merge pull request #297 from andreban/splash-freeze-fix
Browse files Browse the repository at this point in the history
Fixes asynch launchTwa freezing splash screens
  • Loading branch information
andreban authored Jun 7, 2021
2 parents 73b0965 + ec21f95 commit 52f8353
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
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

0 comments on commit 52f8353

Please sign in to comment.