Skip to content

Ability to add splash screen #331

Closed
Closed

Description

@gaurav-chandra

Have the ability to add a splash screen for apps. The post

https://www.nativescript.org/blog/details/splash-screen-for-your-android-applications

is outdated for android 21 and up and results in errors.

Activity

  1. Plamen5kov commented on Jan 12, 2016

    @Plamen5kov
    Contributor

    Hi, @gaurav-chandra
    it would be great if you could provide us with more information like:

    • what errors did you encounter?
    • what device or emulator you tested it on?
  2. gaurav-chandra commented on Jan 13, 2016

    @gaurav-chandra
    Author

    I tested on the device: Lenovo A6000 with Android 5.0.

    The splash screen shows and then the error shows up that activity not found. I guess it has to do with the navigating to the other activity. I will set it up again and add the log here.

  3. gaurav-chandra commented on Jan 13, 2016

    @gaurav-chandra
    Author

    @Plamen5kov these are the errors:

    \platforms\android\src\main\res\values-v21\styles.xml:2 : Error retrieving parent for item: No resource
    found that matches the given name 'NativeScriptToolbarStyleBase'.
    

    build fails. Now I go to

    platforms\android\src\main\res\values-v21\styles.xml
    

    and comment

    <!--<style name="NativeScriptToolbarStyle" parent="NativeScriptToolbarStyleBase">
            <item name="android:elevation">4dp</item>
        </style> -->
    

    and i do

    tns build android
    tns run android
    

    I see the splash screen and then I see:

    java.lang.RuntimeException: Unable to start activity ComponentInfo{cash.ezchange.app/com.tns.NativeScriptActivity}: com.tns.NativeScriptException: 
    Calling js method onCreateView failed
    
    Error: java.lang.RuntimeException: Failed to resolve attribute at index 5
        android.content.res.TypedArray.getColorStateList(TypedArray.java:425)
        android.widget.TextView.<init>(TextView.java:992)
        android.widget.TextView.<init>(TextView.java:634)
        android.support.v7.widget.AppCompatTextView.<init>(AppCompatTextView.java:60)
        android.support.v7.view.menu.ActionMenuItemView.<init>(ActionMenuItemView.java:72)
        android.support.v7.view.menu.ActionMenuItemView.<init>(ActionMenuItemView.java:68)
        java.lang.reflect.Constructor.newInstance(Native Method)
        java.lang.reflect.Constructor.newInstance(Constructor.java:288)
        android.view.LayoutInflater.createView(LayoutInflater.java:607)
        android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
        android.view.LayoutInflater.inflate(LayoutInflater.java:482)
        android.view.LayoutInflater.inflate(LayoutInflater.java:414)
        android.support.v7.view.menu.BaseMenuPresenter.createItemView(BaseMenuPresenter.java:161)
        android.support.v7.view.menu.BaseMenuPresenter.getItemView(BaseMenuPresenter.java:180)
        android.support.v7.widget.ActionMenuPresenter.getItemView(ActionMenuPresenter.java:192)
        android.support.v7.widget.ActionMenuPresenter.flagActionItems(ActionMenuPresenter.java:451)
        android.support.v7.view.menu.MenuBuilder.flagActionItems(MenuBuilder.java:1138)
        android.support.v7.view.menu.BaseMenuPresenter.updateMenuView(BaseMenuPresenter.java:91)
        android.support.v7.widget.ActionMenuPresenter.updateMenuView(ActionMenuPresenter.java:229)
        android.support.v7.view.menu.MenuBuilder.dispatchPresenterUpdate(MenuBuilder.java:284)
        android.support.v7.view.menu.MenuBuilder.onItemsChanged(MenuBuilder.java:1030)
        android.support.v7.view.menu.MenuBuilder.onItemActionRequestChanged(MenuBuilder.java:1076)
        android.support.v7.view.menu.MenuItemImpl.setShowAsAction(MenuItemImpl.java:602)
        com.tns.Platform.callJSMethodNative(Native Method)
        com.tns.Platform.dispatchCallJSMethodNative(Platform.java:799)
        com.tns.Platform.callJSMethod(Platform.java:700)
        com.tns.Platform.callJSMethod(Platform.java:680)
        com.tns.Platform.callJSMethod(Platform.java:670)
        com.tns.gen.android.app.Fragment_ftns_modules_ui_frame_frame_l18_c45__.onCreateView(android.app.Fragment.java)
        android.app.Fragment.performCreateView(Fragment.java:2053)
        android.app.FragmentManagerImpl.moveToState(FragmentManager.java:894)
        android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
        android.app.BackStackRecord.run(BackStackRecord.java:833)
        android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1452)
        android.app.Activity.performStart(Activity.java:6016)
        android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2271)
        android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2368)
        android.app.ActivityThread.access$800(ActivityThread.java:144)
        android.app.ActivityThread$H.handleMessage(ActivityThread.java:1285)
        android.os.Handler.dispatchMessage(Handler.java:102)
        android.os.Looper.loop(Looper.java:135)
        android.app.ActivityThread.main(ActivityThread.java:5233)
        java.lang.reflect.Method.invoke(Native Method)
        java.lang.reflect.Method.invoke(Method.java:372)
        com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:898)
        com.android.internal.os.ZygoteInit.main(ZygoteInit.java:693)
    File: "/data/data/cash.ezchange.app/files/app/tns_modules/ui/action-bar/action-bar.js, line: 236, column: 21
    
    StackTrace: 
    Frame: function:'ActionBar._addActionItems', file:'/data/data/cash.ezchange.app/files/app/tns_modules/ui/action-bar/action-bar.js', line: 236, column: 22
    Frame: function:'ActionBar.update', file:'/data/data/cash.ezchange.app/files/app/tns_modules/ui/action-bar/action-bar.js', line: 129, column: 14
    Frame: function:'ActionBar._createUI', file:'/data/data/cash.ezchange.app/files/app/tns_modules/ui/action-bar/action-bar.js', line: 118, column: 14
    Frame: function:'View._onContextChanged', file:'/data/data/cash.ezchange.app/files/app/tns_modules/ui/core/view.js', line: 202, column: 14
    Frame: function:'View._onAttached', file:'/data/data/cash.ezchange.app/files/app/tns_modules/ui/core/view.js', line: 160, column: 14
    Frame: function:'eachChild', file:'/data/data/cash.ezchange.app/files/app/tns_modules/ui/core/view.js', line: 165, column: 23
    Frame: function:'Page._eachChildView', file:'/data/data/cash.ezchange.app/files/app/tns_modules/ui/page/page-common.js', line: 230, column: 9
    Frame: function:'View._onAttached', file:'/data/data/cash.ezchange.app/files/app/tns_modules/ui/core/view.js', line: 171, column: 18
    Frame: function:'View._addViewCore', file:'/data/data/cash.ezchange.app/files/app/tns_modules/ui/core/view.js', line: 140, column: 18
    Frame: function:'View._addView', file:'/data/data/cash.ezchange.app/files/app/tns_modules/ui/core/view-common.js', line: 869, column: 14
    Frame: function:'onFragmentShown', file:'/data/data/cash.ezchange.app/files/app/tns_modules/ui/frame/frame.js', line: 84, column: 11
    Frame: function:'android.app.Fragment.extend.onCreateView', file:'/data/data/cash.ezchange.app/files/app/tns_modules/ui/frame/frame.js', line: 33, column: 13
    
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2308)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2368)
    at android.app.ActivityThread.access$800(ActivityThread.java:144)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1285)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:135)
    at android.app.ActivityThread.main(ActivityThread.java:5233)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:898)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:693)
    Caused by: com.tns.NativeScriptException: 
    Calling js method onCreateView failed
    
    Error: java.lang.RuntimeException: Failed to resolve attribute at index 5
        android.content.res.TypedArray.getColorStateList(TypedArray.java:425)
        android.widget.TextView.<init>(TextView.java:992)
        android.widget.TextView.<init>(TextView.java:634)
        android.support.v7.widget.AppCompatTextView.<init>(AppCompatTextView.java:60)
        android.support.v7.view.menu.ActionMenuItemView.<init>(ActionMenuItemView.java:72)
        android.support.v7.view.menu.ActionMenuItemView.<init>(ActionMenuItemView.java:68)
        java.lang.reflect.Constructor.newInstance(Native Method)
        java.lang.reflect.Constructor.newInstance(Constructor.java:288)
        android.view.LayoutInflater.createView(LayoutInflater.java:607)
        android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
        android.view.LayoutInflater.inflate(LayoutInflater.java:482)
        android.view.LayoutInflater.inflate(LayoutInflater.java:414)
        android.support.v7.view.menu.BaseMenuPresenter.createItemView(BaseMenuPresenter.java:161)
        android.support.v7.view.menu.BaseMenuPresenter.getItemView(BaseMenuPresenter.java:180)
        android.support.v7.widget.ActionMenuPresenter.getItemView(ActionMenuPresenter.java:192)
        android.support.v7.widget.ActionMenuPresenter.flagActionItems(ActionMenuPresenter.java:451)
        android.support.v7.view.menu.MenuBuilder.flagActionItems(MenuBuilder.java:1138)
        android.support.v7.view.menu.BaseMenuPresenter.updateMenuView(BaseMenuPresenter.java:91)
        android.support.v7.widget.ActionMenuPresenter.updateMenuView(ActionMenuPresenter.java:229)
        android.support.v7.view.menu.MenuBuilder.dispatchPresenterUpdate(MenuBuilder.java:284)
        android.support.v7.view.menu.MenuBuilder.onItemsChanged(MenuBuilder.java:1030)
        android.support.v7.view.menu.MenuBuilder.onItemActionRequestChanged(MenuBuilder.java:1076)
        android.support.v7.view.menu.MenuItemImpl.setShowAsAction(MenuItemImpl.java:602)
        com.tns.Platform.callJSMethodNative(Native Method)
        com.tns.Platform.dispatchCallJSMethodNative(Platform.java:799)
        com.tns.Platform.callJSMethod(Platform.java:700)
        com.tns.Platform.callJSMethod(Platform.java:680)
        com.tns.Platform.callJSMethod(Platform.java:670)
        com.tns.gen.android.app.Fragment_ftns_modules_ui_frame_frame_l18_c45__.onCreateView(android.app.Fragment.java)
        android.app.Fragment.performCreateView(Fragment.java:2053)
        android.app.FragmentManagerImpl.moveToState(FragmentManager.java:894)
        android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
        android.app.BackStackRecord.run(BackStackRecord.java:833)
        android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1452)
        android.app.Activity.performStart(Activity.java:6016)
        android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2271)
        android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2368)
        android.app.ActivityThread.access$800(ActivityThread.java:144)
        android.app.ActivityThread$H.handleMessage(ActivityThread.java:1285)
        android.os.Handler.dispatchMessage(Handler.java:102)
        android.os.Looper.loop(Looper.java:135)
        android.app.ActivityThread.main(ActivityThread.java:5233)
        java.lang.reflect.Method.invoke(Native Method)
        java.lang.reflect.Method.invoke(Method.java:372)
        com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:898)
        com.android.internal.os.ZygoteInit.main(ZygoteInit.java:693)
    File: "/data/data/cash.ezchange.app/files/app/tns_modules/ui/action-bar/action-bar.js, line: 236, column: 21
    
    StackTrace: 
    Frame: function:'ActionBar._addActionItems', file:'/data/data/cash.ezchange.app/files/app/tns_modules/ui/action-bar/action-bar.js', line: 236, column: 22
    Frame: function:'ActionBar.update', file:'/data/data/cash.ezchange.app/files/app/tns_modules/ui/action-bar/action-bar.js', line: 129, column: 14
    Frame: function:'ActionBar._createUI', file:'/data/data/cash.ezchange.app/files/app/tns_modules/ui/action-bar/action-bar.js', line: 118, column: 14
    Frame: function:'View._onContextChanged', file:'/data/data/cash.ezchange.app/files/app/tns_modules/ui/core/view.js', line: 202, column: 14
    Frame: function:'View._onAttached', file:'/data/data/cash.ezchange.app/files/app/tns_modules/ui/core/view.js', line: 160, column: 14
    Frame: function:'eachChild', file:'/data/data/cash.ezchange.app/files/app/tns_modules/ui/core/view.js', line: 165, column: 23
    Frame: function:'Page._eachChildView', file:'/data/data/cash.ezchange.app/files/app/tns_modules/ui/page/page-common.js', line: 230, column: 9
    Frame: function:'View._onAttached', file:'/data/data/cash.ezchange.app/files/app/tns_modules/ui/core/view.js', line: 171, column: 18
    Frame: function:'View._addViewCore', file:'/data/data/cash.ezchange.app/files/app/tns_modules/ui/core/view.js', line: 140, column: 18
    Frame: function:'View._addView', file:'/data/data/cash.ezchange.app/files/app/tns_modules/ui/core/view-common.js', line: 869, column: 14
    Frame: function:'onFragmentShown', file:'/data/data/cash.ezchange.app/files/app/tns_modules/ui/frame/frame.js', line: 84, column: 11
    Frame: function:'android.app.Fragment.extend.onCreateView', file:'/data/data/cash.ezchange.app/files/app/tns_modules/ui/frame/frame.js', line: 33, column: 13
    
    at com.tns.Platform.callJSMethodNative(Native Method)
    at com.tns.Platform.dispatchCallJSMethodNative(Platform.java:799)
    at com.tns.Platform.callJSMethod(Platform.java:700)
    at com.tns.Platform.callJSMethod(Platform.java:680)
    at com.tns.Platform.callJSMethod(Platform.java:670)
    at com.tns.gen.android.app.Fragment_ftns_modules_ui_frame_frame_l18_c45__.onCreateView(android.app.Fragment.java)
    at android.app.Fragment.performCreateView(Fragment.java:2053)
    at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:894)
    at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
    at android.app.BackStackRecord.run(BackStackRecord.java:833)
    at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1452)
    at android.app.Activity.performStart(Activity.java:6016)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2271)
    ... 10 more
    
  4. Plamen5kov commented on Jan 13, 2016

    @Plamen5kov
    Contributor

    update the Android Support Repository from the Android SDK Manager and download Android API level above 22 and try to build again.

  5. gaurav-chandra commented on Jan 13, 2016

    @gaurav-chandra
    Author

    @Plamen5kov no, it did not work. I have all the packages of android installed on my system and I restarted my system also. Same errors as above.

  6. Plamen5kov commented on Jan 13, 2016

    @Plamen5kov
    Contributor

    did you uncomment platforms\android\src\main\res\values-v21\styles.xml ?
    This file is necessary.

  7. gaurav-chandra commented on Jan 13, 2016

    @gaurav-chandra
    Author

    Yes, I did remove the comments and the build failed:

    \platforms\android\src\main\res\values-v21\styles.xml:2 : Error retrieving parent for item: No resource found that matches the given
    name 'NativeScriptToolbarStyleBase'.
    
    :processNativescriptAppResourcesDebugResources FAILED   
    
    
  8. Plamen5kov commented on Jan 13, 2016

    @Plamen5kov
    Contributor

    No resource found that matches the given name 'NativeScriptToolbarStyleBase'. means it can't find

        <style name="NativeScriptToolbarStyleBase" parent="Widget.AppCompat.Toolbar">
            <item name="android:background">@color/ns_primary</item>
            <item name="theme">@style/ThemeOverlay.AppCompat.ActionBar</item>
            <item name="popupTheme">@style/ThemeOverlay.AppCompat</item>
        </style>
    

    which is located in the /src/main/res/values/styles.xml and the content of this file should be:

    <?xml version="1.0" encoding="utf-8"?>
    <resources xmlns:android="http://schemas.android.com/apk/res/android">
        <style name="AppThemeBase" parent="Theme.AppCompat.Light.NoActionBar">
            <item name="toolbarStyle">@style/NativeScriptToolbarStyle</item>
    
            <item name="colorPrimary">@color/ns_primary</item>
            <item name="colorPrimaryDark">@color/ns_primaryDark</item>
            <item name="colorAccent">@color/ns_accent</item>
        </style>
    
        <style name="AppTheme" parent="AppThemeBase">
        </style>
    
        <style name="NativeScriptToolbarStyleBase" parent="Widget.AppCompat.Toolbar">
            <item name="android:background">@color/ns_primary</item>
            <item name="theme">@style/ThemeOverlay.AppCompat.ActionBar</item>
            <item name="popupTheme">@style/ThemeOverlay.AppCompat</item>
        </style>
    
        <style name="NativeScriptToolbarStyle" parent="NativeScriptToolbarStyleBase">
        </style>
    </resources> 
    

    if these files are missing in your project you can remove and add the platform so they get downloaded again or simply replace the values and values-21 folders with those which come from another project.

  9. gaurav-chandra commented on Jan 13, 2016

    @gaurav-chandra
    Author

    Yes, this worked, as I added the xml manually, but only for build. It stills shows the error after the splashscreen. I will investigate further.

  10. Plamen5kov commented on Mar 2, 2016

    @Plamen5kov
    Contributor

    Hi, @gaurav-chandra
    Is there any progress? Did you manage to run the app successfully?

  11. gaurav-chandra commented on Mar 2, 2016

    @gaurav-chandra
    Author

    @Plamen5kov no, I did not. I am running the app without splash screen for now.

  12. gabouh commented on Mar 25, 2016

    @gabouh

    @gaurav-chandra Hi, I did some changes am able to see the splash screen but it's malformed, check the link here :D

  13. gaurav-chandra commented on Mar 25, 2016

    @gaurav-chandra
    Author

    this is something which nativescript should have out of the box without the use of modules as the runtime does take time to load and the user is staring at the white screen during that time.

  14. gabouh commented on Mar 25, 2016

    @gabouh

    yeah it should have it out of the box, Update the workaround and here is a gist

  15. Plamen5kov commented on Aug 8, 2016

    @Plamen5kov
    Contributor

    closed in favor of: #431

  16. PanayotCankov commented on Aug 8, 2016

    @PanayotCankov
    Contributor

    This is implemented, the app ships with splash by default. More information here: https://github.com/NativeScript/docs/blob/master/publishing/creating-launch-screens-android.md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions