title: Finish Activity() from a separate myJavaClass.java
body: <p>I have tried almost all the solutions from SO but no success :(.</p>
  
  <p>I have a simple myJavaClass.java with a couple of functions.</p>
  
  <p>One of the functions in myJavaClass : startActivity() starts MyCustomActivity</p>
  
  <pre><code>public startActivity(Context context)
  {
      Intent intent = new Intent(context, MyCustomActivity.class);
      intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |Intent.FLAG_ACTIVITY_SINGLE_TOP);
      context.startActivity(intent);
  </code></pre>
  
  <p>}</p>
  
  <p>This launches MyCustomActivity() as expected.</p>
  
  <p>Now I have another function in myJavaClass.java to close/finish MyCustomActivity but it is not able to do so!</p>
  
  <p>I have tried </p>
  
  <ol>
  <li><p>Making MyCustomActivity SingleTop in manifest and creating the activity via an intent as above</p></li>
  <li><p>Passing an activity instance to "this" in onCreate() of MyCustomActivity and calling MyCustomActivity.activity.finish() from myJava.class but that doesnt work as well</p></li>
  </ol>
  
  <p>Please help me. I have been stuck here for hours now. I know the solution is very simple and conceptual but I am a newbie. Just building Java/Android concepts!</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>MyCustomActivity</p>
  
  <pre><code>public Activity activity;
  
  OnCreate()
  {
      ...
      this = activity;
  }
  </code></pre>
  
  <p>MyJavaClass</p>
  
  <pre><code>public closeActivity(Context context)
  {
  
          Activity customActivity = MyCustomActivity.activity;
          customActivity.finish();
  }
  </code></pre>