我正在使用 MAT 工具测试我的应用程序,发现存在内存泄漏,但我无法在代码中找到它。请帮助我。
//第一个活动
package intent.sample;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class IntentA extends Activity implements OnClickListener {
Handler handler = new Handler();
private Intent i;
private Button button;
public void onClick(View src) {
if (src == (View) button) {
i = new Intent(this, IntentSampleActivity.class);
handler.postDelayed(new Runnable() {
public void run() {
startActivity(i);
}
}, 20000);
}
}
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main1);
button = (Button) findViewById(R.id.screen2button);
button.setOnClickListener(this);
}
@Override
protected void onStop() {
super.onStop();
this.finish();
}
@Override
protected void onPause() {
super.onPause();
this.finish();
}
@Override
protected void onDestroy() {
super.onDestroy();
handler = null;
i = null;
this.finish();
}
}
//第二个活动
package intent.sample;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class IntentSampleActivity extends Activity implements OnClickListener {
private Button button;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
button = (Button) findViewById(R.id.screen1button);
button.setOnClickListener(this);
}
public void onClick(View scr) {
if (scr == (View) button) {
Intent ii = new Intent(this, IntentA.class);
startActivity(ii);
}
}
@Override
protected void onStop() {
super.onStop();
this.finish();
}
@Override
protected void onPause() {
super.onPause();
this.finish();
}
@Override
protected void onDestroy() {
super.onDestroy();
this.finish();
}
}
我正在创建一个新线程并开始一项活动。这会创建活动类的新实例吗?