我创建了一个从数据库填充并填充到ArrayList的活动
在数据库中添加新数据并调用listview活动时,将ArrayList更改为last,例如6和之前的ArrayList为5项。
当我完成活动时使用以下代码:
Intent intent = new Intent(ListViewClass.this, AddClass.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
ListViewClass.this.onDestroy();
//NamayeshListYadavar.this.finish();
但是当调用ListViewClass时,保存前面的ArrayList和新的ArrayList以及两个ArrayList之间的evrytime切换。
当我调试我的程序时显示2个具有相同名称但不同id和size的ArrayList。我可以在完成活动时删除以前的ArrayList并在我的项目中调用AddClass吗?
我也用
@Override
public void onDestroy() {
super.onDestroy();
Runtime.getRuntime().gc();
}
但是没有工作。
请帮帮我朋友
抱歉英语不好
这是我的所有创建代码
我的所有代码都是:
import java.util.ArrayList;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
import com.blueprogrammers.utils.SomeUtils;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.graphics.Typeface;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.util.TypedValue;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;
public class NamayeshListYadavar extends HeaderFooter {
//AlarmData[] daro_data;
ArrayList<AlarmData> daro_data = new ArrayList<AlarmData>();
Handler mHandler = new Handler();
String myValue;
List<AlarmData> alarmList;
NamayeshListAdaptor adapter;
ListView list;
public String font1="byekan.ttf";
public String font2="BMitraBd.ttf";
private static final int RUN_EDIT = 1100;
/*** 0 for vibre 1 for melody and 2 for melody and vivre***/
int alarmtype = 2, vibre=0;
Boolean animlockBoolean=false;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ViewGroup vg = (ViewGroup) findViewById(R.id.lldata);
ViewGroup.inflate(this, R.layout.yadavar_list, vg);
list = (ListView) findViewById(R.id.yadavar_listview);
createCollection();
adapter = new NamayeshListAdaptor(this,
R.layout.namayeshyadavar, daro_data);
adapter.notifyDataSetChanged();
list.setAdapter(adapter);
list.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0,
android.view.View arg1, int arg2, long arg3) {
// TODO Auto-generated method stub
TextView tv = (TextView) arg1.findViewById(R.id.txtid);
//String text = tv.getText().toString();
myValue = (String) tv.getText();
Intent intent = new Intent(NamayeshListYadavar.this, EditYadavar.class);
intent.putExtra("YADAVAR-ID", myValue);
startActivity(intent);
NamayeshListYadavar.this.finish();
//startActivityForResult(intent, RUN_EDIT);
}
});
Timer timer = new Timer();
timer.schedule(new TimerTask() {
public void run() {
new textSearh().execute();
}
}, 0, 500);
}
public void clickMe(View v){
switch (v.getId()) {
case R.id.txttarikhetmam:
break;
default:
break;
}
}
class textSearh extends AsyncTask<String, String, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
}
protected String doInBackground(String... args) {
runOnUiThread(new Runnable() {
public void run() {
final SharedPreferences preferences = getSharedPreferences("DaroPref", 0);
final int del = preferences.getInt("delid", 9999);
Boolean checkBoolean =preferences.getBoolean("delbol", false);
if(checkBoolean){
Editor editor = preferences.edit();
editor.putBoolean("delbol", false);
editor.commit();
deleteView(del);
}
}
});
return null;
}
protected void onPostExecute(String file_url) {
}
}
private void createCollection() {
DatabaseHandler db= new DatabaseHandler(this);
alarmList = new ArrayList<AlarmData>();
alarmList = db.getViewAlarm("SELECT AlarmID, idDrug, alarmTime , nameYadavar, done, alarmDate FROM Alarm where done =0");
ArrayList<AlarmData> alarm_dat = new ArrayList<AlarmData>(alarmList);
this.daro_data=alarm_dat;
db.close();
}
public void deleteView(final int del){
createCollection2();
Animation anim = AnimationUtils.loadAnimation(
NamayeshListYadavar.this, android.R.anim.slide_out_right
);
try{
anim.setDuration(500);
list.getChildAt(del).startAnimation(anim );
new Handler().postDelayed(new Runnable() {
public void run() {
createCollection2();
adapter = new NamayeshListAdaptor(NamayeshListYadavar.this,
R.layout.namayeshyadavar, daro_data);
adapter.notifyDataSetChanged();
list.setAdapter(adapter);
}
}, anim.getDuration());
}catch(Exception e){
e.printStackTrace();
}
}
public void btnbtnClick(View v)
{
switch (v.getId()) {
case R.id.btnadd:
Intent intent = new Intent(NamayeshListYadavar.this, TanzimSaat.class);
intent.putExtra("CLASS-TYPE", "NamayeshListYadavar");
startActivityForResult(intent, RUN_EDIT);
//startActivityForResult(intent, RUN_EDIT);
break;
case R.id.btnbar:
this.finish();
break;
default:
break;
}
}
@Override
public void onBackPressed() {
this.finish();
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case RUN_EDIT:
createCollection2();
adapter = new NamayeshListAdaptor(this,
R.layout.namayeshyadavar, daro_data);
adapter.notifyDataSetChanged();
list.setAdapter(adapter);
break;
}
}
}
&#13;
最后我通过添加以下代码来解决问题
public void onBackPressed() {
timer.cancel();
this.finish();
}
计时器是我的问题