我有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
的{{1}}。而且我没有看到它正在尝试完成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();
}
}
}
答案 0 :(得分:0)
在Activity2
来电TExecutor
之后,尝试activity1.finishActivity(1)
的关闭Life Cycle中的其他功能。我怀疑Activity2
实际上正在接收onPause()
或onStop()
,而不是onDestroy()
,这只是由系统突发奇想根据资源可用性调用。
答案 1 :(得分:0)
我们实际上已将它们完全转移到单独的应用中。并且改变了结构。