All Products
Search
Document Center

Customize startup loading page

Last Updated: Feb 05, 2021

When the mini program is started, if the mini program has not been downloaded to the device, the mini program container will launch the loading page (as shown in the figure below) to prompt the users to wait. After the mini program is installed on the device, the loading page will be closed and the users will be redirected to the mini program.

Implement a custom loading page

For the Android mini program, mPaaS supports customizing the content of loading page. You can follow the steps below to configure the loading page:

  1. Implement MPTinyBaseIntermediateLoadingView class. The View implemented by this class will be inserted to the Activity where the loading page is. See the sample code below:

       
    1. package com.mpaas.demo.nebula;
    2. import android.content.Context;
    3. import android.util.AttributeSet;
    4. import android.view.LayoutInflater;
    5. import android.widget.TextView;
    6. import com.mpaas.nebula.adapter.api.MPTinyBaseIntermediateLoadingView;
    7. public class TinyStartupLoadingView extends MPTinyBaseIntermediateLoadingView {
    8. private TextView tvAppName;
    9. private TextView tvAppId;
    10. private TextView tvTips;
    11. public TinyStartupLoadingView(Context context) {
    12. super(context);
    13. init();
    14. }
    15. public TinyStartupLoadingView(Context context, AttributeSet attrs) {
    16. super(context, attrs);
    17. init();
    18. }
    19. public TinyStartupLoadingView(Context context, AttributeSet attrs, int defStyleAttr) {
    20. super(context, attrs, defStyleAttr);
    21. init();
    22. }
    23. private void init() {
    24. LayoutInflater.from(getContext()).inflate(R.layout.activity_loading, this, true);
    25. tvAppName = (TextView) findViewById(R.id.app_name);
    26. tvAppId = (TextView) findViewById(R.id.app_id);
    27. tvTips = (TextView) findViewById(R.id.tv_tips);
    28. }
    29. /**
    30. * Call upon initialization, and the App ID will be passed in. Other information, such as App name, icon and version, may be empty.
    31. */
    32. @Override
    33. public void initView(AppInfo info) {
    34. tvAppName.setText(info.appName);
    35. tvAppId.setText(info.appId);
    36. tvTips.setText("loading");
    37. }
    38. /**
    39. * Call when it failed to obtain the mini program
    40. */
    41. @Override
    42. public void onError() {
    43. tvTips.setText("fail");
    44. }
    45. /**
    46. * Call when fetching the mini program App information, including App ID, name, icon and version
    47. */
    48. @Override
    49. public void update(AppInfo info) {
    50. tvAppName.setText(info.appName);
    51. tvAppId.setText(info.appId);
    52. }
    53. }
  2. Before the mini program is started (for example, when the App initialization is ongoing), enable custom configuration. See the code sample below:

       
    1. MPTinyHelper.getInstance().setLoadingViewClass(TinyStartupLoadingView.class);
  3. If you need to operate on the Activity where the custom loading page is, such as interrupting the loading process and backing to the previous page, you can get the Activity through the base class method getLoadingActivity(). Pay attention to checking if the string is empty.