首次启动时卡在启动屏幕上,但如果我们不终止应用程序并再次启动应用程序,则应用程序可以正常工作。 (反应原生)Android
Posted
技术标签:
【中文标题】首次启动时卡在启动屏幕上,但如果我们不终止应用程序并再次启动应用程序,则应用程序可以正常工作。 (反应原生)Android【英文标题】:Stuck on splash screen on first launch but if we don't kill app and launch app again the app works fine. (react-native) Android 【发布时间】:2020-09-07 02:10:01 【问题描述】:我已将代码从 0.53.3 升级到 react-native 0.59.9。我想我可能错过了一些基本步骤并遇到了启动问题。请检查并帮助我使应用正常运行。
React Native Navigation 版本:4.0.6
React Native 版本:0.59.9
设备信息:设备和模拟器两者(所有 Android 版本)。
MainActivity.java
public class MainActivity extends NavigationActivity
static Backbonebits b;
public void addDefaultSplashLayout()
LinearLayout splash = new LinearLayout(this);
Drawable splash_screen_bitmap = ContextCompat.getDrawable(getApplicationContext(),R.drawable.splashscreen);
splash.setBackground(splash_screen_bitmap);
setContentView(splash);
@override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
MobileAds.initialize(this, new OnInitializationCompleteListener()
@override
public void onInitializationComplete(InitializationStatus initializationStatus)
);
b = new Backbonebits(this);
MainApplication.java
public class MainApplication extends NavigationApplication
private static CallbackManager mCallbackManager = CallbackManager.Factory.create();
protected static CallbackManager getCallbackManager()
return mCallbackManager;
@Override
protected ReactGateway createReactGateway()
ReactNativeHost host = new NavigationReactNativeHost(this, isDebug(), createAdditionalReactPackages())
@Override
protected String getJSMainModuleName()
return "index";
;
return new ReactGateway(this, isDebug(), host);
@Override
public boolean isDebug()
return BuildConfig.DEBUG;
protected List<ReactPackage> getPackages()
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new FBSDKPackage(mCallbackManager),
);
@Override
public List<ReactPackage> createAdditionalReactPackages()
return getPackages();
App.js
import React, Component from 'react';
import
Platform
from 'react-native';
import Navigation from 'react-native-navigation'
import TermsOfUseController from "./app/routes/TermsOfUseController"
import Utility from './app/config/Utility';
const registerScreen = (name, component, styles) =>
component.navigatorStyle =
...defaultNavigatorStyles,
...styles
;
Navigation.registerComponent(name, () => component)
function registerAllScreens()
registerScreen('MyApp.LoginController', LoginController, )
registerAllScreens();
User.loggedInUser((user) =>
User.addSignOutListner()
var screenName = 'MyApp.LoginController';
if (user)
if (user.id != 0 && user.id != undefined)
Utility.isFirstTimeLaunch = true
screenName = 'MyApp.HomeScreenController'; // User Already logged in
else
Utility.isFirstTimeLaunch = true
screenName = 'MyApp.LoginController'; // Not Logged in
);
Navigation.events().registerAppLaunchedListener(() =>
Navigation.setRoot(
root:
stack:
children: [
component:
name: screenName,
passProps: ...Navigation
],
options:
topBar:
visible: false
,
);
);
);
【问题讨论】:
【参考方案1】:我在用户检查条件中启动了侦听器。我把它放在外面解决了。它在 android 中产生了问题,但它在 iOS 上运行。
【讨论】:
以上是关于首次启动时卡在启动屏幕上,但如果我们不终止应用程序并再次启动应用程序,则应用程序可以正常工作。 (反应原生)Android的主要内容,如果未能解决你的问题,请参考以下文章
STS启动时卡在loading加载 dashboard.ui