如何显示在闪屏敬酒 [英] How to show toast at Splash Screen

查看:132
本文介绍了如何显示在闪屏敬酒的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

IM上,我有一个主要活动和Activity_splash.xml一个Android应用程序工作
这是我的闪屏的活动。我想是在我的应用程序启动时,如果有互联网连接,启动画面应该出现3秒,这主要活动后,应启动,如果没有互联网打开,那么它应该显示没有网络连接烤面包和开放的无线网络设置和启用WiFi之后,如果返回按钮是pressed,用户应该被带回闪屏......希望这是可以理解的。但我的code未工作作为即时得到一堆错误这是

1。 ACTION_WIRELESS_SETTINGS 不能得到解决或不是场。结果
令牌2.syntax误差{,{预期此令牌后,(在网上公开级闪屏扩展 活动{)
令牌(,;预期和语法上的错误标记)3.syntax错误; 预计(在网上保护无效的onCreate(捆绑savedInstanceState){)

SplashScreen.java

 公共类闪屏延伸活动{
如果(!NetworkCheckClass.haveNetworkConnection(SplashActivity.this)){
    Toast.makeText(SplashScreen.this,没有互联网连接!,Toast.LENGTH_LONG).show();    意向意图=新意图(Settings.ACTION_WIRELESS_SETTINGS);
    startActivity(意向);
}
其他{
    //你的code如果连接可用
} //闪屏计时器
    私有静态诠释SPLASH_TIME_OUT = 3000;    @覆盖
    保护无效的onCreate(捆绑savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.activity_splash);        新的处理程序()。postDelayed(新的Runnable(){            / *
             *显示启动画面用计时器。这将是有益的,当你
             *希望出现在您的应用程序标识/公司
             * /            @覆盖
            公共无效的run(){
                //一旦定时结束该方法将被执行
                //开始您的应用程序主要活动
                意图I =新意图(SplashScreen.this,MainActivity.class);
                startActivity(ⅰ);                //关闭此活动
                完();
            }
        },SPLASH_TIME_OUT);
    }
  }
  }


解决方案

您的活动下面写下code中的OnCreate():

 如果(!NetworkCheckClass.haveNetworkConnection(SplashActivity.this)){
Toast.makeText(SplashScreen.this,没有互联网连接!,Toast.LENGTH_LONG).show();意向意图=新意图(Settings.ACTION_WIRELESS_SETTINGS);
startActivity(意向);
}
其他{
 //你的code如果连接可用
} //闪屏计时器

im working on an android application in which i have a main activity and Activity_splash.xml which is my splash screen activity. what i want is when my app is launched, and if there is internet connection, the splash screen should appear for 3 seconds and after that main activity should launch and if there is No internet turned on, then it should show "No internet connection " toast and open wireless networks settings and after enabling wifi, if return button is pressed, user should be brought back to splash screen... hope this is understandable.. but my code is not working as im getting bunch of errors which are

1.ACTION_WIRELESS_SETTINGS cannot be resolved or is not a field.
2.syntax error on token "{",{ expected after this token (in line public class SplashScreen extends Activity {) 3.syntax error on token "(",; expected and syntax error on token ")",; expected (in line protected void onCreate(Bundle savedInstanceState) {)

SplashScreen.java

public class SplashScreen extends Activity {
if (!NetworkCheckClass.haveNetworkConnection(SplashActivity.this)) {
    Toast.makeText(SplashScreen.this, "No internet connection!",             Toast.LENGTH_LONG).show();

    Intent intent=new Intent(Settings.ACTION_WIRELESS_SETTINGS);
    startActivity(intent);
}
else {
    // your code if connection is available
} // Splash screen timer
    private static int SPLASH_TIME_OUT = 3000;

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

        new Handler().postDelayed(new Runnable() {

            /*
             * Showing splash screen with a timer. This will be useful when you
             * want to show case your app logo / company
             */

            @Override
            public void run() {
                // This method will be executed once the timer is over
                // Start your app main activity
                Intent i = new Intent(SplashScreen.this, MainActivity.class);
                startActivity(i);

                // close this activity
                finish();
            }
        }, SPLASH_TIME_OUT);
    }
  }
  }

解决方案

Write below code in OnCreate() of your activity :

if (!NetworkCheckClass.haveNetworkConnection(SplashActivity.this)) {
Toast.makeText(SplashScreen.this, "No internet connection!",             Toast.LENGTH_LONG).show();

Intent intent=new Intent(Settings.ACTION_WIRELESS_SETTINGS);
startActivity(intent);
}
else {
 // your code if connection is available
} // Splash screen timer

这篇关于如何显示在闪屏敬酒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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