Skip to content Skip to sidebar Skip to footer

How To Show Toast At Splash Screen

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 ther

Solution 1:

try this

publicclassSplashScreenextendsActivity {
static ConnectivityManager cm;
AlertDialog dailog;
AlertDialog.Builder build;

@OverrideprotectedvoidonCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    build = newBuilder(Context); 

    if (cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI)
            .isConnectedOrConnecting()
            || cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE)
                    .isConnectedOrConnecting()// if connection is// there screen goes// to next screen// else shows// message toast
    ) {
        Log.e("cm value", "" + cm.getAllNetworkInfo().toString());
        Toast.makeText(SplashScreen.this, "Internet is active", 2000)
                .show();
        Threadmythread=newThread() {
            publicvoidrun() {
                try {

                    sleep(5000);

                } catch (Exception e) {
                } finally {
                    Intentintent=newIntent(SplashScreen.this,
                            Yournextactivity.class);
                    startActivity(intent);
                    finish();
                }
            }
        };
        mythread.start();
    } else {

        build.setMessage("This application requires Internet connection.Would you connect to internet ?");
        build.setPositiveButton("Yes", newOnClickListener() {

            @OverridepublicvoidonClick(DialogInterface dialog, int which) {
                // TODO Auto-generated method stub
                finish();
                startActivity(newIntent(Settings.ACTION_WIFI_SETTINGS));

            }
        });
        build.setNegativeButton("No", newOnClickListener() {

            @OverridepublicvoidonClick(DialogInterface dialog, int which) {
                // TODO Auto-generated method stub
                build.setMessage("Are sure you want to exit?");
                build.setPositiveButton("Yes", newOnClickListener() {

                    @OverridepublicvoidonClick(DialogInterface dialog, int which) {
                        // TODO Auto-generated method stub
                        finish();
                    }
                });
                build.setNegativeButton("NO", newOnClickListener() {

                    @OverridepublicvoidonClick(DialogInterface dialog, int which) {
                        // TODO Auto-generated method stub
                        finish();
                        Intentintent=newIntent(SplashScreen.this,
                                SplashScreen.class);
                        startActivity(intent);

                        dialog.dismiss();

                    }
                });
                dailog = build.create();
                dailog.show();
            }
        });
        dailog = build.create();
        dailog.show();

    }

}

@OverridepublicbooleanonCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    returntrue;
}

Solution 2:

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

Solution 3:

privatevoidchecknetworkavailability() {
    // TODO Auto-generated method stubConnectivityManagercm=
                (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
            NetworkInfonetInfo= cm.getActiveNetworkInfo();
            if (netInfo != null && netInfo.isConnectedOrConnecting()) {

                // call your intent
            }
            else{
                Toast.makeText(context, "Please Check Your Internet connection", Toast.LENGTH_LONG).show();
                Timertimer=newTimer();
                timer.schedule(newTimerTask() {

                   @Overridepublicvoidrun() {

                 //  call settings intent

                   }

                }, 3000);

            }

}

use this method checknetworkavailability..

Post a Comment for "How To Show Toast At Splash Screen"