Gluon Android startup screen

I used gluon mobile to create a small mobile application, and now I have conducted a beta test through Google play. But I realized that the speed of starting a mobile application on my Android device is very slow (it takes more than 10 seconds)

If I can add a splashScreen before loading the application, that's great, so users won't wait a total of 10 times, but they feel only half, because they get the response of the application when they see the splashScreen

In the development of native Android, we only established two activities (one for splashScreen and one for main applications), such as blow:

<activity
android:name=”.SplashScreen”>
<intent-filter>
<action android:name=”android.intent.action.MAIN” />
<category android:name=”android.intent.category.LAUNCHER” />
</intent-filter>
</activity>
<activity
android:name=”.MainActivity”
android:label=”@string/app_name”
>
<intent-filter>
<action android:name=”android.intent.action.MAIN” />
</intent-filter>
</activity>

My question is, is there any way to display splashScreen built on JavaFX / gluon, which will run on Android / IOS instead of local. If we are based on JavaFX instead of this native method, there are any disadvantages

Since the age of using gluon / JavaFX on mobile devices is very young, it is difficult to obtain the ideal method of best practice. Please illuminate me

gr

resolvent:

While launching the screen may be a good idea, in fact, the gluon mobile multi view project created using the gluon plug-in allows you to create similar effects by using the home view as a placeholder for images or any other lightweight content to display, while loading all heavy content into the secondary view

By default, the main view is the initial view loaded during the application. Start() method. Other views will not be loaded until the user switches to other views

Using the following view, the actual load of the load will start only when the user clicks the floating operation button, but the startup view on the mobile device will not be displayed immediately:

public class SplashView extends View {

    public SplashView(String name) {
        super(name);

        setCenter(new ImageView(new Image(getClass().getResourceAsStream("splash.png"))));

        FloatingActionButton action = new FloatingActionButton(MaterialDesignIcon.ARROW_FORWARD.text, e -> 
                MobileApplication.getInstance().switchView(GluonSplash.SECONDARY_VIEW));
        getLayers().add(action);
    }

    @Override
    protected void updateAppBar(AppBar appBar) {
        appBar.setVisible(false);
    }

}

In order to avoid user intervention, you can cancel the operation button and start loading the second view after displaying the startup screen for a certain time

In another example, after the initial view is displayed, the transition will begin to pause. After one second, it will display a label to indicate that a new view will be loaded. At the same time, start the task of loading the view. After all heavyweight views are loaded, it will be displayed

public class SplashView extends View {

    public SplashView(String name) {
        super(name);

        Label access = new Label("Accessing...");
        access.setTranslateY(200);
        access.setVisible(false);
        setCenter(new StackPane(new ImageView(new Image(getClass().getResourceAsStream("splash.png"))), 
                            access));

        Task<Void> task = new Task<Void>() {

            @Override
            protected Void call() throws Exception {
                Platform.runLater(() -> MobileApplication.getInstance().switchView(GluonSplash.SECONDARY_VIEW));
                return null;
            }
        };

        addEventHandler(LifecycleEvent.SHOWN, e -> {
            PauseTransition pause = new PauseTransition(Duration.seconds(1));
            pause.setOnFinished(f -> {
                access.setVisible(true);
                new Thread(task).start();
            });
            pause.play();
        });

    }

    @Override
    protected void updateAppBar(AppBar appBar) {
        appBar.setVisible(false);
    }

}

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>