Finishing a child Activity, in a different process, from parent Activity. finishActivity() not working
<p>I have an <code>Activity</code> [Activity1] that starts a <code>Runnable</code> called [ProRunnable] and in the <code>run()</code> of <code>ProRunnable</code> i have an instance of a class called [TExecutor] that i call a method on.</p>

<p>That method then starts another <code>Activity</code> [Activity2] for result. The <code>Activity2</code> starts a <code>Callable</code> with <code>ExecutorService</code>.</p>

<p><code>TExecutor</code> contains a reference to <code>Activity1</code>. <strong>How can i force <code>Activity2</code> to finish from outside <code>Activity2</code>? I need <code>Activity2</code> to finish and the <code>Callable</code> to stop running too.</strong></p>

<p>I have tried <code>activity1.finishActivity(1)</code> where "1" is the request code i used to start <code>Activity2</code> in <code>TExecutor</code>. But it never calls the <code>onDestroy</code> of <code>Activity2</code>. And i do not see that it is trying to finish the <code>Activity2</code>.</p>

<p>After i make the call for the activity to finish, it does not appear to go into <code>onDestroy</code> and the callable continues to run.</p>

<p><code>Activity2</code> has no theme, so it basically runs in the background. It is also in a different process. I set all this in the manifest, shown at bottom.</p>

<p>Sounds confusing, i know. If you need more information, let me know.</p>

<p>Thanks</p>

<hr>

<pre><code>public class Activity1 extends FragmentActivity {

    private ProRunnable proRunnable;
    private Thread thread;

    public onStart() {

        this.proRunnable = new ProRunnable(this);
        this.thread = new Thread(this.proRunnable);
        this.thread.start();
    }

    ON BUTTON PRESS {

        this.finishActivity(Activity2.REQUEST_CODE);
    }

    protected void onActivityResult(int reqCode, int resCode, Intent data) {

        if(reqCode == Activity2.REQUEST_CODE) {

            //do stuff
        }
    }
}
</code></pre>

<hr>

<pre><code>public class ProRunnable implements Runnable {

    private TExecutor tExecutor;
    private Activity activty1;

    public ProRunnable(Activity activity) {

        this.activity1 = activity;
    }

    public void run() {

        this.tExecutor = new TExecutor(this.activity1);
        this.tExecutor.execute();
    }
}
</code></pre>

<hr>

<pre><code>public final class TExecutor {

    private final Activity activity1;
    private Intent activity2Intent;

    public TExecutor(Activity activity) {

        this.activity1 = activity;
    }

    public void execute() {

        this.activity2Intent = new Intent(activity1.getBaseContext(), Activity2.class);
        this.activity2Intent.startActivityForResult(this.activity2Intent, Activity2.REQUEST_CODE);
    }
}
</code></pre>

<hr>

<pre><code>public class Activity2 extends Activity {

    public static final int REQUEST_CODE = 1;
    private ExecutorService executor;

    protected void onStart() {

        Intent returnIntent = new Intent();
        InsertThread insert = new InserterThread();
        this.executor = Executors.newSingleThreadExecutor();
        Future&lt;Boolean&gt; submit = this.executor.submit(inserter);

        try {

            submit.get();
        } catch ... {
        }
    }

    private class InserterThread implements Callable&lt;Boolean&gt; {

        public InserterThread() {

        }

        public Boolean call() throws ... {

            while(!Thread.currentThread().isInterrupted()) {

                for(...) {

                    if(Thread.currentThread().isInterrupted()) {

                        break;
                    }
                }
            }
        }

        protected void onDestroy() {

            super.onDestroy();
            Log.e(TAG, "DESTROYING THE ACTIVITY");
            this.executor.shutdownNow();
        }
    }
}
</code></pre>

<hr>

<pre><code>&lt;manifest...&gt;
    &lt;application android:process="package.path.p1"&gt;
        &lt;activity android:name="package.path.Activity1"/&gt;
        &lt;activity android:name="package.path.Activity2" android:process="package.path.p2" android:theme="@android:style/Theme.NoDisplay"/&gt;
    &lt;/application&gt;
&lt;/manifest&gt;
</code></pre>
