Skip to content

Instantly share code, notes, and snippets.

@Pradeepg89
Created August 29, 2016 12:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Pradeepg89/e533e51f0277b1edaf96ac7eb8b859ce to your computer and use it in GitHub Desktop.
Save Pradeepg89/e533e51f0277b1edaf96ac7eb8b859ce to your computer and use it in GitHub Desktop.
in my project on splash screen load i am checking if url is rechable in thread and when it is not reachable show alert screen
for that i am using
@Override
protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_splash);
super.onCreate(savedInstanceState);
Thread t =new Thread()
{
@Override
public void run() {
try
{
sleep(2000);
if (isURLReachable(SplashActivity.this)) {
Log.d("server", "reachable");
}
else
{
Log.d("server","unreachable");
showAlertDialog();
}}
catch (InterruptedException e)
{
e.printStackTrace();
}
super.run();
}
};
t.start();
}
/*************/
protected void showAlertDialog()
{
AlertDialog.Builder alertdialog=new AlertDialog.Builder(this);
alertdialog.setMessage("Server is not reachable.Please try Again.");
alertdialog.setCancelable(false);
alertdialog.setPositiveButton("OK",new DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface dialogInterface, int id) {
finish();
dialogInterface.cancel();
}
});
alertdialog.show();
}
but my application is getting crashed
please suggest me
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment