我有一个Activity
[Activity1],它启动了一个Runnable
名为 [ProRunnable] 的对象,并且在其中run()
我ProRunnable
有一个名为 [TExecutor] 的类的实例,我调用了一个方法。
然后该方法启动另一个Activity
[Activity2] 以获得结果。以Activity2
开头。Callable
_ExecutorService
TExecutor
包含对 的引用Activity1
。我怎样才能强制Activity2
从外面完成Activity2
?我需要Activity2
完成并Callable
停止运行。
我试过activity1.finishActivity(1)
“1”是我用来开始的请求Activity2
代码TExecutor
。但它从不调用onDestroy
of 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>