title: How to close the activity from the service?
body: <p>I am launching activity from the service based on some value got from the server and the activity will be displayed for the some time and after getting close instruction from the server i need to close that activity,so for that i used following approach but it's not working:
   on Service class:</p>
  
  <pre><code>if(((ActivityManager)this.getSystemService(ACTIVITY_SERVICE)).getRunningTasks(1).get(0).topActivity.getPackageName().equals("com")) {
  
  if(((ActivityManager)this.getSystemService(ACTIVITY_SERVICE)).getRunningTasks(1).get(0).topActivity.getClassName().equals("com.CustomDialogActivity")){
  Intent dialogIntent = new Intent(getBaseContext(), CustomDialogActivity.class);
               dialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);               
               dialogIntent.putExtra("description", "");
               dialogIntent.putExtra("cancelEnabled", false);
               dialogIntent.putExtra("close", true);
              getApplication().startActivity(dialogIntent);
  
  
  }
      }
  </code></pre>
  
  <p>and on activity inside onCreate method:</p>
  
  <pre><code>Bundle bundle = getIntent().getExtras();
  boolean isClosed = bundle.getBoolean("close");
      if(isClosed){        
          finish();
   }
  </code></pre>
  
  <p>I debugged it and found that control reaches to the onCreate method if(isClosed) condition and executed finish() method also but its not closing the activity.</p>
  
  <p>so Couldn't be able to analyze what wrong I am doing.</p>