how to get first running process?
<p>i am creating a service for my security application which will check after every second if the particular process is started and will pop up the dialog box for password.and anyone can use that application only if he/she will enter the password. my problem is that my timer repeatedly show dialog box. so i apply "c" variable to run this dialog for once but this will appear only once i started the app. after that! app is opening directly without showing dialog box first` </p>

<pre><code>private static Timer timer = new Timer(); 
        private Context ctx;
      private  int c=0;
    @Override
    public IBinder onBind(Intent arg0) {
        // TODO Auto-generated method stub
        return null;
    }
      public void onCreate() 
        {
              super.onCreate();
              ctx = this; 
              startService();
        }

        private void startService()
        {           
            timer.scheduleAtFixedRate(new mainTask(), 0, 5000);
        }

        private class mainTask extends TimerTask
        { 
            public void run() 
            {
                toastHandler.sendEmptyMessage(0);
            }
        }   
    @Override
    public int onStartCommand(Intent intent, int flag,int startId){
        /* Timer timer = new Timer();
            timer.scheduleAtFixedRate(new TimerTask() {
                public void run() {   


                                dial();
                            }
                        }                       
                     }
                   }, 0, 1000);*/
        return START_STICKY;    
    }
    @Override
    public void onDestroy(){

        super.onDestroy();
        timer.cancel();
        Toast.makeText(this, "Service Stoped", Toast.LENGTH_LONG).show();
    }
     private final Handler toastHandler = new Handler()
        {
            @Override
            public void handleMessage(Message msg)
            {
                Toast.makeText(getApplicationContext(), "test", Toast.LENGTH_SHORT).show();
                ActivityManager actvityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
            List&lt;RunningAppProcessInfo&gt; procInfos = actvityManager.getRunningAppProcesses();
            for(int i = 0; i &lt; procInfos.size(); i++){
                if(procInfos.get(i).processName.equals("com.android.music")) {
                    Toast.makeText(getApplicationContext(), "music is running", Toast.LENGTH_LONG).show();
                  c++;
                  if(c==1){
                    int pid = android.os.Process.getUidForName("com.android.music");
                     android.os.Process.killProcess(pid);
                    Intent ii = new Intent();
                       ii.setClass(APP_SeeL_Password.this,Setappdetail.class);
                       ii.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                       startActivity(ii); 
                  }
                    //timer.cancel();
                  }
                } 
           }
        };  ` 
</code></pre>

<p>and here is my dialog activity</p>

<pre><code>    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.custom_dialoge);
    LayoutParams params = getWindow().getAttributes(); 
    params.width = LayoutParams.FILL_PARENT; 
     getWindow().setAttributes((android.view.WindowManager.LayoutParams) params);
    // TODO Auto-generated method stub

EditText et=(EditText)findViewById(R.id.editText2);
  str=et.getText().toString();
  LockOrNot getpinvar=new LockOrNot(this);
     getpinvar.open();
      ptr=getpinvar.getpin(1);
     getpinvar.close();
Button okb=(Button)findViewById(R.id.button1);
</code></pre>

<p>okb.setOnClickListener(new View.OnClickListener() {</p>

<pre><code>    public void onClick(View arg0) {
        // TODO Auto-generated method stub

        if(str.equals(ptr)==true){
        Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage("com.android.music");
        startActivity( LaunchIntent );}
    }
});
Button cancelb=(Button)findViewById(R.id.button2);
cancelb.setOnClickListener(new View.OnClickListener() {

    public void onClick(View arg0) {
        // TODO Auto-generated method stub
        Intent startMain = new Intent(Intent.ACTION_MAIN);
        startMain.addCategory(Intent.CATEGORY_HOME);
        startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(startMain);
    }
});
</code></pre>

<p>}</p>
