fix memory leak
This commit is contained in:
parent
f1da548fb8
commit
2ecde80fbd
@ -22,6 +22,7 @@ import android.widget.FrameLayout;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
@ -41,7 +42,6 @@ import pub.doric.utils.DoricUtils;
|
||||
*/
|
||||
public class DemoActivity extends AppCompatActivity {
|
||||
private DoricContext doricContext;
|
||||
private DevPanel devPanel = new DevPanel();
|
||||
private SensorManagerHelper sensorHelper;
|
||||
|
||||
@Override
|
||||
@ -59,10 +59,11 @@ public class DemoActivity extends AppCompatActivity {
|
||||
sensorHelper.setOnShakeListener(new SensorManagerHelper.OnShakeListener() {
|
||||
@Override
|
||||
public void onShake() {
|
||||
if (devPanel.isAdded()) {
|
||||
Fragment devPanel = getSupportFragmentManager().findFragmentByTag("DevPanel");
|
||||
if (devPanel != null && devPanel.isAdded()) {
|
||||
return;
|
||||
}
|
||||
devPanel.show(getSupportFragmentManager(), "DevPanel");
|
||||
new DevPanel().show(getSupportFragmentManager(), "DevPanel");
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -107,7 +108,7 @@ public class DemoActivity extends AppCompatActivity {
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
if (KeyEvent.KEYCODE_MENU == event.getKeyCode()) {
|
||||
devPanel.show(getSupportFragmentManager(), "DevPanel");
|
||||
new DevPanel().show(getSupportFragmentManager(), "DevPanel");
|
||||
}
|
||||
return super.onKeyDown(keyCode, event);
|
||||
}
|
||||
|
@ -32,11 +32,9 @@ import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import pub.doric.dev.DevPanel;
|
||||
import pub.doric.utils.DoricUtils;
|
||||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
private DevPanel devPanel = new DevPanel();
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@ -91,10 +89,6 @@ public class MainActivity extends AppCompatActivity {
|
||||
tv.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (position == 0) {
|
||||
devPanel.show(getSupportFragmentManager(), "DevPanel");
|
||||
return;
|
||||
}
|
||||
Intent intent = new Intent(tv.getContext(), DemoActivity.class);
|
||||
intent.putExtra("source", data[position]);
|
||||
tv.getContext().startActivity(intent);
|
||||
|
@ -40,6 +40,8 @@ import pub.doric.utils.DoricUtils;
|
||||
* @CreateDate: 2019-07-18
|
||||
*/
|
||||
public class DoricJSEngine implements Handler.Callback, DoricTimerExtension.TimerCallback {
|
||||
|
||||
private HandlerThread handlerThread;
|
||||
private final Handler mJSHandler;
|
||||
private final DoricBridgeExtension mDoricBridgeExtension = new DoricBridgeExtension();
|
||||
private IDoricJSE mDoricJSE;
|
||||
@ -47,7 +49,7 @@ public class DoricJSEngine implements Handler.Callback, DoricTimerExtension.Time
|
||||
private final DoricRegistry mDoricRegistry = new DoricRegistry();
|
||||
|
||||
public DoricJSEngine(final boolean isNative, final IStatusCallback statusCallback) {
|
||||
HandlerThread handlerThread = new HandlerThread(this.getClass().getSimpleName());
|
||||
handlerThread = new HandlerThread(this.getClass().getSimpleName());
|
||||
handlerThread.start();
|
||||
Looper looper = handlerThread.getLooper();
|
||||
mJSHandler = new Handler(looper, this);
|
||||
@ -171,6 +173,8 @@ public class DoricJSEngine implements Handler.Callback, DoricTimerExtension.Time
|
||||
public void teardown() {
|
||||
mDoricJSE.teardown();
|
||||
mTimerExtension.teardown();
|
||||
handlerThread.quit();
|
||||
mJSHandler.removeCallbacksAndMessages(null);
|
||||
}
|
||||
|
||||
private void loadBuiltinJS(String assetName) {
|
||||
|
Reference in New Issue
Block a user