0

currently I have my app setup to ping a server when the activity is loaded, and its working, but in the process the app goes to a black screen while it pings all the servers. I wanted to make it so all the servers ping in the background, and the user can still operate the app while its doing so. Heres my code:

        Runtime runtime = Runtime.getRuntime();
        Process  mIpAddrProcess = runtime.exec("/system/bin/ping -c 1 sfb.noip.me");
        int mExitValue = mIpAddrProcess.waitFor();
        Process  mIpAddrProcess2 = runtime.exec("/system/bin/ping -c 1 sg.lbsg.net");
        int mExitValue2 = mIpAddrProcess2.waitFor();
        Process  mIpAddrProcess3 = runtime.exec("/system/bin/ping -c 1 peepzcraft.zapto.org");
        int mExitValue3 = mIpAddrProcess3.waitFor();
        Process  mIpAddrProcess4 = runtime.exec("/system/bin/ping -c 1 71.226.128.188");
        int mExitValue4 = mIpAddrProcess4.waitFor();
        Process  mIpAddrProcess5 = runtime.exec("/system/bin/ping -c 1 playmcpe.com");
        int mExitValue5 = mIpAddrProcess5.waitFor();
        Process  mIpAddrProcess6 = runtime.exec("/system/bin/ping -c 1 survival.dgpocket.us");
        int mExitValue6 = mIpAddrProcess6.waitFor();
        Process  mIpAddrProcess7 = runtime.exec("/system/bin/ping -c 1 
        minecraft.blocksandgold.com");
        int mExitValue7 = mIpAddrProcess7.waitFor();
        Process  mIpAddrProcess8 = runtime.exec("/system/bin/ping -c 1 pe.cookie-build.com");
        int mExitValue8 = mIpAddrProcess8.waitFor();
        Process  mIpAddrProcess9 = runtime.exec("/system/bin/ping -c 1 96.8.119.195");
        int mExitValue9 = mIpAddrProcess9.waitFor();
        Process  mIpAddrProcess10 = runtime.exec("/system/bin/ping -c 1 Play.mcpe-ba.info");
        int mExitValue10 = mIpAddrProcess10.waitFor();
        Process  mIpAddrProcess11 = runtime.exec("/system/bin/ping -c 1 64.94.238.196");
        int mExitValue11 = mIpAddrProcess11.waitFor();
        Process  mIpAddrProcess12 = runtime.exec("/system/bin/ping -c 1 leet.cc");
        int mExitValue12 = mIpAddrProcess12.waitFor();
        Process  mIpAddrProcess13 = runtime.exec("/system/bin/ping -c 1 ru.24serv.pro");
        int mExitValue13 = mIpAddrProcess13.waitFor();
        if(mExitValue==0){

            text.setText("Server Status: Online");              
        }else{
            text.setText("Server Status: Offline");              
        }
dogger20011
  • 255
  • 2
  • 13
  • 1
    Read up on AsyncTask, a builtin way to do stuff on a seperate thread so the app isn't blocked. Also your code could be made a whole lot cleaner with a loop, but that's a different matter – Tim Dec 12 '14 at 23:09
  • Here is a solution already on SO to use AsyncTask to ping: http://stackoverflow.com/a/9063257/2777098 – display name Dec 12 '14 at 23:10

0 Answers0