0

I am developing an app in which I read all app package from my device and set to some class. I want to jump from loop when a specified package comes like "com.example.abc".How can I do that

@Override
protected Void doInBackground(Void... params)
{
    boolean exit=false;
    int currentIndex=0;

    try
    {
        PackageInfo pi=null;
        int scannedApps=0;
        int menacesFound=0;

        while(running && currentIndex<_packagesToScan.size())
        {
            Thread.sleep(100);

            if(!_isPaused)
            {

                pi = _packagesToScan.get(currentIndex);

                dtp.scannedFiles = currentIndex;
                dtp.appName = pi.packageName;
                dtp.icon = StaticTools.getIconFromPackage(dtp.appName, _activity);
                dtp.totalFiles = _packagesToScan.size();

                boolean b = isPackageInMenacesSet(dtp.appName);
                if (b)
                    dtp.foundMenaces++;

                publishProgress(dtp);

                ++scannedApps;
                ++currentIndex;
            }
        }
    }
    catch(InterruptedException ex)
    {
        Log.w("APP", "Scanning task was interrupted");
    }

    return null;
}
niraj kumar
  • 103
  • 2
  • 2
  • 9

2 Answers2

0

use "break"

while(true)
{ 
   if(condition)
        break;
}
p.streef
  • 3,652
  • 3
  • 26
  • 50
0

Use break; when your package is found to get out of the loop.

If you want to enter into next iteration of the loop without getting out of it then use continue; command. For more information about break and continue check this.

Community
  • 1
  • 1
Vishal Puri
  • 823
  • 8
  • 15