简体   繁体   English

如何使用广告优化 android 应用程序的启动时间

[英]How to optimize startup time for android application with Ads

I created a simple mobile app that plays a single music track ( as a practice ), and I have added one banner Ad in the onCreate Method as seen the code snippets below.我创建了一个播放单个音乐曲目的简单移动应用程序(作为练习),并在 onCreate 方法中添加了一个横幅广告,如下面的代码片段所示。

However, the startup time has increased several seconds more than before which is really annoying for a user experience.但是,启动时间比以前增加了几秒钟,这对于用户体验来说确实很烦人。 Is there a way to add the Ads to the app and reduce the startup time for the app.有没有办法将广告添加到应用程序并减少应用程序的启动时间。

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);


    // Adding Banner Add
    MobileAds.initialize(this, new OnInitializationCompleteListener() {
        @Override
        public void onInitializationComplete(InitializationStatus initializationStatus) {
        }
    });
    AdView mAdView = findViewById(R.id.adView1);
    AdRequest adRequest = new AdRequest.Builder().build();
    mAdView.loadAd(adRequest);



    m1 = MediaPlayer.create(this, R.raw.short_sound);


    Button playSong = findViewById(R.id.playSong);
    Button stopSong = findViewById(R.id.stopSong);
    Button reset = findViewById(R.id.reset);

Consider loading the ad on a separate thread:考虑在单独的线程上加载广告:

new Runnable()
{
    @Override
    public void run()
    {
        MobileAds.initialize(this, new OnInitializationCompleteListener()
        {
            @Override
            public void onInitializationComplete(InitializationStatus initializationStatus)
            {
            }
        });
        AdRequest adRequest = new AdRequest.Builder().build();
    }
}.run();

Then load the result on to View on the main thread like so:然后将结果加载到主线程上的 View 中,如下所示:

runOnUiThread(...set component to ui...);

You must make sure that the ad view is initialized with some placeholder display first.您必须确保首先使用一些占位符显示初始化广告视图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM