[ProRunnable]という名前の[ Activity
Activity1]があり、その中にメソッドを呼び出す[TExecutor]というクラスのインスタンスがあります。Runnable
run()
ProRunnable
次に、そのメソッドはActivity
結果のために別の[Activity2]を開始します。はでActivity2
始まりCallable
ますExecutorService
。
TExecutor
への参照が含まれていますActivity1
。どうすればActivity2
外部から強制的に終了できActivity2
ますか?私Activity2
も終了する必要があり、Callable
実行を停止する必要があります。
「1」はで開始するためにactivity1.finishActivity(1)
使用したリクエストコードです。ただし、のを呼び出すことはありません。そして、私はそれが終了しようとしているのを見ていません。Activity2
TExecutor
onDestroy
Activity2
Activity2
アクティビティを終了するための呼び出しを行った後、アクティビティが開始されていないように見えonDestroy
、呼び出し可能オブジェクトは実行を続けます。
Activity2
テーマがないため、基本的にバックグラウンドで実行されます。また、別のプロセスにあります。これらすべてを、下部に表示されているマニフェストに設定しました。
紛らわしいように聞こえます、私は知っています。さらに詳しい情報が必要な場合は、お知らせください。
ありがとう
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
}
}
}
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();
}
}
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);
}
}
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<Boolean> submit = this.executor.submit(inserter);
try {
submit.get();
} catch ... {
}
}
private class InserterThread implements Callable<Boolean> {
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();
}
}
}
<manifest...>
<application android:process="package.path.p1">
<activity android:name="package.path.Activity1"/>
<activity android:name="package.path.Activity2" android:process="package.path.p2" android:theme="@android:style/Theme.NoDisplay"/>
</application>
</manifest>