【问题标题】:Finishing The Splash Activity?完成飞溅活动?
【发布时间】:2014-02-28 01:01:42
【问题描述】:

通过屏幕按钮进入主屏幕然后再次单击应用程序打开它时,启动屏幕不会完成,它只是返回到启动屏幕?为什么会这样

我正在调用finish();那么为什么它不会混淆

package com.webcraftbd.radio;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.preference.PreferenceManager;

public class SplashScreen extends Activity
{
    // Set the display time, in milliseconds (or extract it out as a configurable parameter)
    private final int SPLASH_DISPLAY_LENGTH = 3000;

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

    @Override
    protected void onResume()
    {
        super.onResume();
        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
        // Obtain the sharedPreference, default to true if not available
        boolean isSplashEnabled = sp.getBoolean("isSplashEnabled", true);

        if (isSplashEnabled)
        {
            new Handler().postDelayed(new Runnable()
            {
                @Override
                public void run()
                {
                    //Finish the splash activity so it can't be returned to.
                    SplashScreen.this.finish();
                    // Create an Intent that will start the main activity.
                    Intent mainIntent = new Intent(SplashScreen.this, MainActivity.class);
                    SplashScreen.this.startActivity(mainIntent);
                }
            }, SPLASH_DISPLAY_LENGTH);
        }
        else
        {
            // if the splash is not enabled, then finish the activity immediately and go to main.
            finish();
            Intent mainIntent = new Intent(SplashScreen.this, MainActivity.class);
            SplashScreen.this.startActivity(mainIntent);
        }
    }}

【问题讨论】:

  • 试试这个: Intent mainIntent = new Intent(SplashScreen.this, MainActivity.class); SplashScreen.this.startActivity(mainIntent);SplashScreen.this.finish();你应该先 startActivity 然后完成你的启动画面。
  • 你为什么首先使用启动画面?这是一个 Android 反模式,违反了设计准则。
  • 我尝试过让您知道它是否有效。因为在我看来,它让应用看起来更专业,所以很多应用使用闪屏可能会导致其他内容加载
  • 这里有很多启动画面:stackoverflow.com/questions/21989199/…
  • 谢谢 ;) 不知道为什么当前的没有工作,然后从你的管子上取下来,所以它应该可以工作,我之前运气好就完成了这个教程

标签: android android-activity splash-screen


【解决方案1】:

如果它只是一个闪屏,为什么你不使用简单的东西?喜欢;

protected void onCreate(Bundle radioPlayer) {
        super.onCreate(radioPlayer);
        setContentView(R.layout.main);

        Thread splash= new Thread(){
            public void run(){
                try{
                    sleep(3000);
                    startActivity(new Intent("com.test.MAINMENU"));
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                finally {
                    finish();
                }
            }

        };
        splash.start();
    }

【讨论】:

  • 试过没用:/在主 fest xml 中我确实将它设置为启动屏幕,因为主启动器可能是为什么但没有其他人有奇怪的问题,谢谢 ;)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多