如何使一个启动画面加载一次? [英] How do I make a splash screen load once?

查看:293
本文介绍了如何使一个启动画面加载一次?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以...我已经开发了成功运行的启动画面。我怎样才能使它运行一次(也是唯一一次)?我想建立一个注册页面,但我只希望它出现在用户一次。

帮助!

阿曼尼斯旺

 进口android.app.Activity;
进口android.os.Bundle;
进口android.os.Handler;
进口android.content.Intent;
进口com.nfc.linkingmanager.R;公共类闪屏延伸活动{私人布尔mIsBackButton pressed;
私有静态最终诠释SPLASH_DURATION = 1000;公共无效的onCreate(捆绑savedInstanceState){
    super.onCreate(savedInstanceState);    的setContentView(R.layout.splash_screen);    处理程序处理程序=新的处理程序();
    handler.postDelayed(新的Runnable(){        @覆盖
        公共无效的run(){            完();            如果(!mIsBackButton pressed){                意向意图=新意图(SplashScreen.this,NewCore.class);
                SplashScreen.this.startActivity(意向);
           }        }    },SPLASH_DURATION);} @覆盖
 公共无效onBack pressed(){
    mIsBackButton pressed = TRUE;
    super.onBack pressed();}
}


解决方案

使用的 共享preferences 存储的屏幕已经显示的事实;在启动时,你检查这一点,如果是这样,你通过启动下一个,并调用的 完成() 闪现屏幕立即生效。

So... I've developed a splash screen which is running successfully. How can I make it run once (and only once)? I'd like to build a registration screen but I only want it to appear for the user once.

Help!

Amani Swann

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.content.Intent;
import com.nfc.linkingmanager.R;

public class SplashScreen extends Activity {

private boolean mIsBackButtonPressed;
private static final int SPLASH_DURATION = 1000; 

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.splash_screen);

    Handler handler = new Handler();


    handler.postDelayed(new Runnable() {

        @Override
        public void run() {



            finish();

            if (!mIsBackButtonPressed) {

                Intent intent = new Intent(SplashScreen.this, NewCore.class);
                SplashScreen.this.startActivity(intent);
           }

        }

    }, SPLASH_DURATION);

}

 @Override
 public void onBackPressed() {
    mIsBackButtonPressed = true;
    super.onBackPressed();

}
}

解决方案

Use SharedPreferences to store the fact that the screen has already been displayed; upon start, you check this and if so, you replace the Activity by starting the next one and calling finish() for the splash screen immediately.

这篇关于如何使一个启动画面加载一次?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆