本文介绍了方法onDestroy()不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我运行我的应用程序,所有的复选框被选中在我的 ListView ,但我不希望他们在开始检查。
我想我没有正确写 onDestroy()



请帮帮我! p>

这是我的代码:



适配器:

  public abstract class PlanetAdapter extends ArrayAdapter< Planet> implements CompoundButton.OnCheckedChangeListener {

private List< Planet> planetList = null;
private Context context = null;
ArrayList< Birra>对象;
private HashMap< Integer,Planet> pizzaSelected = new HashMap<>();
public boolean Checked;

public PlanetAdapter(List< Planet> planetList,Context context){
super(context,R.layout.single_listview_item,planetList);
this.planetList = planetList;
this.context = context;
}


public class PlanetHolder {
public TextView planetName;
public TextView distView;
public TextView valuta;
public CheckBox chkBox;
public EditText edit;
// public Stringquantità;
public boolean checked;
public TextView id;
}

@Override
public int getCount(){
return planetList.size();
}

@Override
public Planet getItem(int position){
return planetList.get(position);
}

@Override
public long getItemId(int position){
return planetList.get(position).getId();
}


@Override
public View getView(final int position,View convertView,ViewGroup parent){

View row = convertView ;
PlanetHolder holder = null;

if(row == null){
LayoutInflater inflater =((Activity)context).getLayoutInflater();
row = inflater.inflate(R.layout.single_listview_item,parent,false);
holder = new PlanetHolder();
holder.planetName =(TextView)row.findViewById(R.id.name);
holder.distView =(TextView)row.findViewById(R.id.dist);
holder.valuta =(TextView)row.findViewById(R.id.valuta);
holder.chkBox =(CheckBox)row.findViewById(R.id.chk_box);
holder.edit =(EditText)row.findViewById(R.id.editText);
holder.edit.setVisibility(View.GONE);
holder.edit.setEnabled(false);
// holder.id =(TextView)row.findViewById(R.id.id);

row.setTag(holder);

} else {
holder =(PlanetHolder)row.getTag();
}

final Planet p = planetList.get(position);
holder.planetName.setText(p.getName());
holder.distView.setText(+ p.getDistance());
holder.valuta.setText(+ p.getValuta());
holder.chkBox.setChecked(p.isSelected());
holder.chkBox.setTag(p);
holder.edit.setEnabled(false);
SharedPreferences states = getContext()。getSharedPreferences(states,Context.MODE_PRIVATE);
boolean isChecked = states.getBoolean(holder.chkBox+ holder.planetName.getText()。toString(),false);
System.out.println(isChecked);

if(isChecked){
holder.chkBox.setChecked(true);
holder.edit.setVisibility(View.VISIBLE);
holder.edit.setEnabled(true);
SharedPreferences statess = getContext()。getSharedPreferences(states,Context.MODE_PRIVATE);
String string = statess.getString(finalHolder.edit+ holder.planetName.getText()。toString(),holder.edit.getText()。toString()。trim());
holder.edit.setText(string);

} else {
holder.chkBox.setChecked(false);
holder.edit.setVisibility(View.GONE);
holder.edit.setEnabled(false);

}

holder.chkBox.setOnCheckedChangeListener(PlanetAdapter.this);
// final BirraHolder finalHolder = birraHolder;
final PlanetHolder finalHolder = holder;

holder.chkBox.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v){
if(finalHolder.chkBox.isChecked ()$ {
finalHolder.edit.setVisibility(View.VISIBLE);
finalHolder.edit.setEnabled(true);
SharedPreferences states = getContext()。getSharedPreferences .MODE_PRIVATE);
SharedPreferences.Editor editor = states.edit();
editor.putBoolean(holder.chkBox+ finalHolder.planetName.getText()。toString(),true);
editor.commit();
finalHolder.edit.addTextChangedListener(new TextWatcher(){
@Override
public void beforeTextChanged(CharSequence s,int start,int count,int after){ }

@Override
public void onTextChanged(CharSequence s,int start,int before,int count){}

@Override
public void afterTextChanged (可编辑){
p.setQuantità(finalHolder.edit.getText()。toString()。trim());
SharedPreferences states = getContext()。getSharedPreferences(states,Context.MODE_PRIVATE);
SharedPreferences.Editor editor = states.edit();
editor.putString(finalHolder.edit+ finalHolder.planetName.getText()。toString(),finalHolder.edit.getText()。toString()。trim());
editor.commit();
}
});

/ * SharedPreferences states = getContext()。getSharedPreferences(states,Context.MODE_PRIVATE);
SharedPreferences.Editor editor = states.edit();
editor.putBoolean(holder.chkBox+ finalHolder.planetName.getText()。toString(),true);
editor.commit(); * /
//Utility.putPizzaItem(p);
//Utility.getPizzaItem(p);


} else {
SharedPreferences states = getContext()。getSharedPreferences(states,Context.MODE_PRIVATE);
SharedPreferences.Editor editor3 = states.edit();
finalHolder.edit.setVisibility(View.GONE);
finalHolder.edit.setEnabled(false);
finalHolder.edit.setText();
/ * editor3.putBoolean(holder.chkBox+ finalHolder.planetName.getText()。toString(),false);
editor3.commit(); * /

}
/ * SharedPreferences states = getContext()。getSharedPreferences(states,Context.MODE_PRIVATE);
SharedPreferences.Editor editor = states.edit();
editor.apply(); * /

}
});
/ * holder.chkBox.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v){
if(finalHolder.chkBox.isChecked ){
finalHolder.edit.setVisibility(View.VISIBLE);
finalHolder.edit.setEnabled(true);
SharedPreferences states = getContext()。getSharedPreferences(states,Context.MODE_PRIVATE );
SharedPreferences.Editor editor = states.edit();
editor.putBoolean(holder.chkBox,true);
//pizzaSelected.put(p.getId p);
System.out.println(p.getId());
} else {

finalHolder.edit.setVisibility(View.GONE);
finalHolder.edit.setEnabled(false);
finalHolder.edit.setText(null);
pizzaSelected.remove(p.getId());

}

}
}); * /


/ * finalHolder.edit.addTextChangedListener(new TextWatcher(){
@Override
public void beforeTextChanged(CharSequence s,int start,int count, int after){
}

@Override
public void onTextChanged(CharSequence s,int start,int before,int count){
}

@Override
public void afterTextChanged(可编辑){
p.setQuantità(finalHolder.edit.getText()。toString()。trim());
SharedPreferences states = getContext ().getSharedPreferences(states,Context.MODE_PRIVATE);
SharedPreferences.Editor editor = states.edit();
editor.putString(finalHolder.edit+ finalHolder.planetName.getText .toString(),finalHolder.edit.getText()。toString()。trim());
editor.commitmit();
}
}); * /

// holder.planetName.setText(p.getName());
// holder.distView.setText(+ p.getDistance());
// holder.valuta.setText(+ p.getValuta());
// holder.chkBox.setChecked(p.isSelected());
// holder.chkBox.setTag(p);
// holder.edit.setEnabled(false);
// holder.id.setId(p.getId());


return row;
}

ArrayList< Planet> getBox(){
ArrayList< Planet> box = new ArrayList< planet>();
for(Planet p:planetList){
if(p.isSelected())
box.add(p);
}
return box;
}

}

strong>

  public class MyListFragment extends Fragment implements 
android.widget.CompoundButton.OnCheckedChangeListener {

ListView lv;
ArrayList< Planet> planetList;
static PlanetAdapter plAdapter;

BirraAdapter biAdapter;
PlanetAdapter.PlanetHolder holder;
private static上下文上下文= null;
private static FragmentActivity mInstance;

@Override
public View onCreateView(LayoutInflater inflater,ViewGroup container,
Bundle savedInstanceState){
//为此片段扩充布局
ViewGroup rootView =(ViewGroup)inflater.inflate(R.layout.fragment_list2,container,false);
context = getActivity();
mInstance = getActivity();
Button mButton =(Button)rootView.findViewById(R.id.button);
mButton.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
showResult(v);
}
});
// return inflater.inflate(R.layout.fragment_list2,container,false);
return rootView;
}

@Override
public void onViewCreated(View view,@Nullable Bundle savedInstanceState){
super.onViewCreated(view,savedInstanceState);

lv =(ListView)getView()。findViewById(R.id.listview);
displayPlanetList();

}

private void displayPlanetList(){

planetList = new ArrayList&
planetList.add(new Planet(Margherita,6,€,1));
planetList.add(new Planet(Diavola,7,€,2));
planetList.add(new Planet(Bufalina,5,€,3));
planetList.add(new Planet(Marinara,5,€,4));
planetList.add(new Planet(Viennese,4,€,5));

plAdapter = new PlanetAdapter(planetList,getContext()){
@Override
public void onCheckedChanged(CompoundButton buttonView,boolean isChecked){

int pos = lv.getPositionForView(buttonView);
if(pos!= ListView.INVALID_POSITION){
Planet p = planetList.get(pos);
p.setSelected(isChecked);


/*Toast.makeText(
getActivity(),
点击Pizza:+ p.getName()+。State:is
+ isChecked,Toast.LENGTH_SHORT).show(); * /
}
}
};

lv.setAdapter(plAdapter);
}



public void onCheckedChanged(CompoundButton buttonView,boolean isChecked){

/ * int pos = lv.getPositionForView );
if(pos!= ListView.INVALID_POSITION){
Planet p = planetList.get(pos);
p.setSelected(isChecked);

* // * Toast.makeText(
getActivity(),
点击Planet:+ p.getName()+。State:is
+ isChecked,Toast.LENGTH_SHORT).show(); * // *
} * /

}

/ *
public static void showResult(View v){
String result =所选产品是:;
int totalAmount = 0;
String result2 =;
int totalAmount2 = 0;

String a =;
String z =;

for(Planet p:plAdapter.getBox()){
if(p.isSelected()){
result2 + =\\\
+ p.getName )++ p.getDistance()+€+q.tà:+p.getQuantità();
int quantitaInt = Integer.parseInt(p.getQuantità());
totalAmount2 + = p.getDistance()* quantitaInt;
//z=String.valueOf(totalAmount2);
}
int totale = totalAmount + totalAmount2;
z = String.valueOf(totale);
}

Toast.makeText(context,result2 +\\\
+Total Amount:=+ totalAmount2 +€,Toast.LENGTH_LONG).show
//Toast.makeText(getActivity(),result2 +\\\
+Total Amount:=+ totalAmount2 +€,Toast.LENGTH_LONG).show


Bundle bun2 = new Bundle();
bun2.putString(scelta,result2);
ThreeFragment fgsearch2 = new ThreeFragment();
fgsearch2.setArguments(bun2);
android.support.v4.app.FragmentTransaction transaction2 = mInstance.getSupportFragmentManager()。beginTransaction();
transaction2.replace(R.id.content_main,fgsearch2);
transaction2.commit();
} * /

public static void showResult(View v){
String result =Selected Product are:;
int totalAmount = 0;
String result2 =;
int totalAmount2 = 0;

String a =;
// String z =;

for(Planet p:plAdapter.getBox()){
if(p.isSelected()){

result + =\\\
p.getName()++ p.getDistance()+€+q.tà:+p.getQuantità();
int quantitaInt = Integer.parseInt(p.getQuantità());
totalAmount2 + = p.getDistance()* quantitaInt;
// z = String.valueOf(totalAmount2);
}
}

Toast.makeText(context,result +\\\
+Total Amount:=+ totalAmount2 +€,Toast.LENGTH_LONG)。显示();
// Toast.makeText(getActivity(),result2 +\\\
+Total Amount:=+ totalAmount2 +€,Toast.LENGTH_LONG).show


Bundle bun2 = new Bundle();
bun2.putString(scelta3,result);
TwoFragment fgsearch2 = new TwoFragment();
fgsearch2.setArguments(bun2);
android.support.v4.app.FragmentTransaction transaction2 = mInstance.getSupportFragmentManager()。beginTransaction();
transaction2.replace(R.id.content_main3,fgsearch2);
transaction2.commit();

/ * Bundle bun = new Bundle();
// bun.putString(totalepizze,z);
bun.putInt(totalepizze,totalAmount2);
TwoFragment fgsearch = new TwoFragment();
fgsearch.setArguments(bun);
android.support.v4.app.FragmentTransaction transaction = mInstance.getSupportFragmentManager()。beginTransaction();
transaction.replace(R.id.content_main2,fgsearch);
transaction.commit(); * /

/ * Bundle bun = new Bundle();
bun.putString(scelta,result2);
TwoFragment fgsearch = new TwoFragment();
fgsearch.setArguments(bun);
android.support.v4.app.FragmentTransaction transaction = getActivity()。getSupportFragmentManager()。beginTransaction();
transaction.replace(R.id.content_main2,fgsearch);
transaction.commit(); * /
}

}

活动:

  public class Main extends AppCompatActivity {


@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

getSupportFragmentManager()。beginTransaction()
.replace(R.id.fragmentContainer,new MyListFragment())。commit();

}

@Override
public void onDestroy(){
super.onDestroy();
SharedPreferences myPrefs = this.getSharedPreferences(states,
Context.MODE_PRIVATE);
myPrefs.edit()。remove(states);
myPrefs.edit()。clear();
myPrefs.edit()。commit();
}
}

LOGCAT:

  05-22 13:40:33.781 12076-12076 /? D / dalvikvm:不晚启用CheckJNI(已经打开)
05-22 13:40:34.831 12076-12081 / info.androidhive.materialtabs I / dalvikvm:threadid = 3:对信号3作出反应
05-22 13:40:35.190 12076-12081 / info.androidhive.materialtabs I / dalvikvm:将堆栈跟踪写入到'/data/anr/traces.txt'
05-22 13:40:35.331 12076-12081 /info.androidhive.materialtabs I / dalvikvm:threadid = 3:对信号3作出反应
05-22 13:40:35.411 12076-12081 / info.androidhive.materialtabs I / dalvikvm: /anr/traces.txt'
05-22 13:40:35.761 12076-12081 / info.androidhive.materialtabs I / dalvikvm:threadid = 3:对信号3作出反应
05-22 13:40 :35.810 12076-12081 / info.androidhive.materialtabs I / dalvikvm:将堆栈跟踪写到'/data/anr/traces.txt'
05-22 13:40:35.871 12076-12076 / info.androidhive.materialtabs W / dalvikvm:VFY:无法找到签名中引用的类(Landroid / view / SearchEvent;)
05-22 13:40:35.880 12076-12076 / info.androidhive.materialtabs I / dalvikvm:无法找到方法android.view.Window $ Callback.onSearchRequested,从方法引用android.support.v7.view.WindowCallbackWrapper.onSearchRequested
05-22 13:40:35.880 12076-12076 / info.androidhive.materialtabs W / dalvikvm:VFY :无法解析接口方法18907:Landroid / view / Window $ Callback; .onSearchRequested(Landroid / view / SearchEvent;)Z
05-22 13:40:35.880 12076-12076 / info.androidhive.materialtabs D / dalvikvm:VFY:替换操作码0x72在0x0002
05-22 13:40:35.890 12076-12076 / info.androidhive.materialtabs I / dalvikvm:无法找到方法android.view.Window $ Callback.onWindowStartingActionMode,引用方法android.support.v7.view.WindowCallbackWrapper.onWindowStartingActionMode
05-22 13:40:35.890 12076-12076 / info.androidhive.materialtabs W / dalvikvm:VFY:无法解析接口方法18911:Landroid / view / Window $ Callback; .onWindowStartingActionMode(Landroid / view / ActionMode $ Callback; I)Landroid / view / ActionMode;
05-22 13:40:35.890 12076-12076 / info.androidhive.materialtabs D / dalvikvm:VFY:将操作码0x72替换为0x0002
05-22 13:40:36.191 12076-12076 / info。 androidhive.materialtabs I / dalvikvm:找不到方法android.view.ViewGroup.onRtlPropertiesChanged,从方法引用android.support.v7.widget.Toolbar.onRtlPropertiesChanged
05-22 13:40:36.221 12076-12076 / info .androidhive.materialtabs W / dalvikvm:VFY:无法解析虚拟方法18802:Landroid / view / ViewGroup; .onRtlPropertiesChanged(I)V
05-22 13:40:36.221 12076-12076 / info.androidhive.materialtabs D / dalvikvm:VFY:替换操作码0x6f 0x0007
05-22 13:40:36.281 12076-12081 / info.androidhive.materialtabs I / dalvikvm:threadid = 3:对信号3作出反应
05- 22 13:40:36.351 12076-12076 / info.androidhive.materialtabs I / dalvikvm:无法找到方法android.content.res.TypedArray.getChangingConfigurations,从方法引用android.support.v7.widget.TintTypedArray.getChangingConfigurations
05-22 13:40:36.351 12076-12076 / info.androidhive.materialtabs W / dalvikvm:VFY:无法解析虚拟方法442:Landroid / content / res / TypedArray; .getChangingConfigurations()I
05- 22 13:40:36.351 12076-12076 / info.androidhive.materialtabs D / dalvikvm:VFY:替换操作码0x6e在0x0002
05-22 13:40:36.361 12076-12076 / info.androidhive.materialtabs I / dalvikvm :无法找到方法android.content.res.TypedArray.getType,从方法引用android.support.v7.widget.TintTypedArray.getType
05-22 13:40:36.371 12076-12076 / info.androidhive.materialtabs W / dalvikvm:VFY:无法解析虚拟方法464:Landroid / content / res / TypedArray; .getType(I)I
05-22 13:40:36.371 12076-12076 / info.androidhive.materialtabs D / dalvikvm:VFY:替换操作码0x6e在0x0002
05-22 13:40:36.401 12076-12081 / info.androidhive.materialtabs I / dalvikvm:写堆栈跟踪到'/data/anr/traces.txt'
05-22 13:40:36.531 12076-12076 / info.androidhive.materialtabs I / dalvikvm:找不到方法android.widget.LinearLayout $ LayoutParams。< init>,从方法android.support.design.widget引用.AppBarLayout $ LayoutParams。< init>
05-22 13:40:36.561 12076-12076 / info.androidhive.materialtabs W / dalvikvm:VFY:无法解析直接方法19435:Landroid / widget / LinearLayout $ LayoutParams;。< init> (Landroid / widget / LinearLayout $ LayoutParams;)V
05-22 13:40:36.561 12076-12076 / info.androidhive.materialtabs D / dalvikvm:VFY:将操作码0x70替换为0x0000
05-22 13:40:36.561 12076-12076 / info.androidhive.materialtabs I / dalvikvm:无法找到方法android.widget.LinearLayout $ LayoutParams。< init>,从方法android.support.design.widget.AppBarLayout $ LayoutParams引用。 < init>
05-22 13:40:36.571 12076-12076 / info.androidhive.materialtabs W / dalvikvm:VFY:无法解析直接方法19435:Landroid / widget / LinearLayout $ LayoutParams;。< init& (Landroid / widget / LinearLayout $ LayoutParams;)V
05-22 13:40:36.571 12076-12076 / info.androidhive.materialtabs D / dalvikvm:VFY:将操作码0x70替换为0x0000
05-22 13:40:36.771 12076-12081 / info.androidhive.materialtabs I / dalvikvm:threadid = 3:对信号3作出反应
05-22 13:40:36.771 12076-12079 / info.androidhive.materialtabs D / dalvikvm :GC_CONCURRENT释放217K,3%释放12838K / 13127K,暂停14ms + 6ms
05-22 13:40:36.841 12076-12081 / info.androidhive.materialtabs I / dalvikvm:写堆栈跟踪到/ data / anr /traces.txt'
05-22 13:40:36.970 12076-12076 / info.androidhive.materialtabs I / dalvikvm:找不到方法android.content.res.Resources.getDrawable,从方法android.support引用.v7.widget.ResourcesWrapper.getDrawable
05-22 13:40:36.970 12076-12076 / info.androidhive.materialtabs W / dalvikvm:VFY:无法解析虚拟方法405:Landroid / content / res / Resources; .getDrawable(ILandroid / content / res / Resources $ Theme;)Landroid / graphics / drawable / Drawable;
05-22 13:40:36.970 12076-12076 / info.androidhive.materialtabs D / dalvikvm:VFY:将操作码0x6e替换为0x0002
05-22 13:40:36.970 12076-12076 / info。 androidhive.materialtabs I / dalvikvm:找不到方法android.content.res.Resources.getDrawableForDensity,从方法引用android.support.v7.widget.ResourcesWrapper.getDrawableForDensity
05-22 13:40:36.980 12076-12076 /info.androidhive.materialtabs W / dalvikvm:VFY:无法解析虚拟方法407:Landroid / content / res / Resources; .getDrawableForDensity(IILandroid / content / res / Resources $ Theme;)Landroid / graphics / drawable / Drawable;
05-22 13:40:36.980 12076-12076 / info.androidhive.materialtabs D / dalvikvm:VFY:将操作码0x6e替换为0x0002
05-22 13:40:37.261 12076-12081 / info。 android / dalvikvm:编译堆栈跟踪到/ data / anr / android / html / traces.txt'
05-22 13:40:37.671 12076-12076 / info.androidhive.materialtabs W / FragmentManager:moveToState:TwoFragment的片段状态{4160a840#1 id = 0x7f0c006b android:switcher:2131492971:1}未更新内联;预期状态3找到2
05-22 13:40:37.701 12076-12076 / info.androidhive.materialtabs W / FragmentManager:moveToState:Fragment state for ThreeFragment {41676830#2 id = 0x7f0c006b android:switcher:2131492971:2 }未内联更新;预期状态3找到2
05-22 13:40:37.711 12076-12076 / info.androidhive.materialtabs W / FragmentManager:moveToState:FourFragment的片段状态{41639f98#3 id = 0x7f0c006b android:switcher:2131492971:3 }未内联更新;预期状态3找到2
05-22 13:40:37.731 12076-12076 / info.androidhive.materialtabs W / FragmentManager:moveToState:FiveFragment的片段状态{4160d458#4 id = 0x7f0c006b android:switcher:2131492971:4 }未内联更新;预期状态3找到2
05-22 13:40:37.741 12076-12076 / info.androidhive.materialtabs W / FragmentManager:moveToState:SixFragment的片段状态{4164fde0#5 id = 0x7f0c006b android:switcher:2131492971:5 }未内联更新;预期状态3找到2
05-22 13:40:37.771 12076-12081 / info.androidhive.materialtabs I / dalvikvm:threadid = 3:对信号3作出反应
05-22 13:40:37.811 12076-12076 / info.androidhive.materialtabs W / FragmentManager:moveToState:SevenFragment的片段状态{41660860#6 id = 0x7f0c006b android:switcher:2131492971:6}未内嵌更新;预期状态3找到2
05-22 13:40:37.832 12076-12081 / info.androidhive.materialtabs I / dalvikvm:将堆栈跟踪写入到'/data/anr/traces.txt'
05- 22 13:40:37.861 12076-12076 / info.androidhive.materialtabs W / FragmentManager:moveToState:EightFragment的片段状态{41654958#7 id = 0x7f0c006b android:switcher:2131492971:7}未内联更新;预期状态3找到2
05-22 13:40:37.891 12076-12076 / info.androidhive.materialtabs W / FragmentManager:moveToState:NineFragment的片段状态{41643a90#8 id = 0x7f0c006b android:switcher:2131492971:8 }未内联更新;预期状态3找到2
05-22 13:40:37.911 12076-12076 / info.androidhive.materialtabs W / FragmentManager:moveToState:TenFragment的片段状态{41614fa8#9 id = 0x7f0c006b android:switcher:2131492971:9 }未内联更新;预期状态3找到2
05-22 13:40:38.270 12076-12081 / info.androidhive.materialtabs I / dalvikvm:threadid = 3:对信号3作出反应
05-22 13:40:38.331 12076-12081 / info.androidhive.materialtabs I / dalvikvm:将堆栈跟踪写到'/data/anr/traces.txt'
05-22 13:40:38.481 12076-12076 / info.androidhive.materialtabs I / System.out:true
05-22 13:40:38.641 12076-12079 / info.androidhive.materialtabs D / dalvikvm:GC_CONCURRENT释放139K,2%释放13161K / 13383K,暂停6ms + 6ms
05 -22 13:40:38.781 12076-12081 / info.androidhive.materialtabs I / dalvikvm:threadid = 3:对信号3作出反应
05-22 13:40:38.861 12076-12076 / info.androidhive.materialtabs I /System.out:true
05-22 13:40:38.871 12076-12081 / info.androidhive.materialtabs I / dalvikvm:将堆栈跟踪写到'/data/anr/traces.txt'
05 -22 13:40:39.010 12076-12076 / info.androidhive.materialtabs I / System.out:true
05-22 13:40:39.100 12076-12076 / info.androidhive.materialtabs I / System.out: true
05-22 13:40:39.171 12076-12076 / info.androidhive.materialtabs I / System.out:true
05-22 13:40:39.290 12076-12081 / info.androidhive.materialtabs I / dalvikvm:threadid = 3:对信号3作出反应
05-22 13:40:39.311 12076-12081 / info.androidhive.materialtabs I / dalvikvm:写堆栈跟踪到'/data/anr/traces.txt '
05-22 13:40:39.771 12076-12081 / info.androidhive.materialtabs I / dalvikvm:threadid = 3:对信号3作出反应
05-22 13:40:39.811 12076-12081 / info.androidhive.materialtabs I / dalvikvm:写堆栈跟踪到'/data/anr/traces.txt'
05-22 13:40:40.150 12076-12076 / info.androidhive.materialtabs D / gralloc_goldfish:检测到GPU模拟。
05-22 13:40:40.280 12076-12081 / info.androidhive.materialtabs I / dalvikvm:threadid = 3:对信号3作出反应
05-22 13:40:40.311 12076-12081 / info .androidhive.materialtabs I / dalvikvm:将堆栈跟踪写入到/data/anr/traces.txt


解决方案

onDestroy不能保证被调用。



您可以使用onBackPressed或onPause代替


When I run my app, all the checkboxes are checked in my ListView but I don't want them checked at the start.I think I didn't write onDestroy() correctly.

Please help me!

Here is my code:

Adapter:

public abstract class PlanetAdapter extends ArrayAdapter<Planet> implements CompoundButton.OnCheckedChangeListener {

    private List<Planet> planetList = null;
    private Context context = null;
    ArrayList<Birra> objects;
    private HashMap<Integer, Planet> pizzaSelected = new HashMap<>();
    public boolean Checked;

    public PlanetAdapter(List<Planet> planetList, Context context) {
        super(context, R.layout.single_listview_item, planetList);
        this.planetList = planetList;
        this.context = context;
    }


    public class PlanetHolder {
        public TextView planetName;
        public TextView distView;
        public TextView valuta;
        public CheckBox chkBox;
        public EditText edit;
        //public String quantità;
        public boolean checked;
        public TextView id;
    }

    @Override
    public int getCount() {
        return planetList.size();
    }

    @Override
    public Planet getItem(int position) {
        return planetList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return planetList.get(position).getId();
    }


    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {

        View row = convertView;
        PlanetHolder holder = null;

        if (row == null) {
            LayoutInflater inflater = ((Activity) context).getLayoutInflater();
            row = inflater.inflate(R.layout.single_listview_item, parent, false);
            holder = new PlanetHolder();
            holder.planetName = (TextView) row.findViewById(R.id.name);
            holder.distView = (TextView) row.findViewById(R.id.dist);
            holder.valuta = (TextView) row.findViewById(R.id.valuta);
            holder.chkBox = (CheckBox) row.findViewById(R.id.chk_box);
            holder.edit = (EditText) row.findViewById(R.id.editText);
            holder.edit.setVisibility(View.GONE);
            holder.edit.setEnabled(false);
            // holder.id = (TextView) row.findViewById(R.id.id);

            row.setTag(holder);

        } else {
            holder = (PlanetHolder) row.getTag();
        }

        final Planet p = planetList.get(position);
        holder.planetName.setText(p.getName());
        holder.distView.setText("" + p.getDistance());
        holder.valuta.setText("" + p.getValuta());
        holder.chkBox.setChecked(p.isSelected());
        holder.chkBox.setTag(p);
        holder.edit.setEnabled(false);
        SharedPreferences states = getContext().getSharedPreferences("states", Context.MODE_PRIVATE);
        boolean isChecked = states.getBoolean("holder.chkBox" + holder.planetName.getText().toString(), false);
        System.out.println(isChecked);

        if (isChecked) {
            holder.chkBox.setChecked(true);
            holder.edit.setVisibility(View.VISIBLE);
            holder.edit.setEnabled(true);
            SharedPreferences statess = getContext().getSharedPreferences("states", Context.MODE_PRIVATE);
            String string = statess.getString("finalHolder.edit" + holder.planetName.getText().toString(), holder.edit.getText().toString().trim());
            holder.edit.setText(string);

        } else {
            holder.chkBox.setChecked(false);
            holder.edit.setVisibility(View.GONE);
            holder.edit.setEnabled(false);

         }

        holder.chkBox.setOnCheckedChangeListener(PlanetAdapter.this);
        // final BirraHolder finalHolder = birraHolder;
        final PlanetHolder finalHolder = holder;

        holder.chkBox.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (finalHolder.chkBox.isChecked()) {
                    finalHolder.edit.setVisibility(View.VISIBLE);
                    finalHolder.edit.setEnabled(true);
                    SharedPreferences states = getContext().getSharedPreferences("states", Context.MODE_PRIVATE);
                    SharedPreferences.Editor editor = states.edit();
                    editor.putBoolean("holder.chkBox" + finalHolder.planetName.getText().toString(), true);
                    editor.commit();
                    finalHolder.edit.addTextChangedListener(new TextWatcher() {
                        @Override
                        public void beforeTextChanged(CharSequence s, int start, int count, int after) {}

                        @Override
                        public void onTextChanged(CharSequence s, int start, int before, int count) {}

                        @Override
                        public void afterTextChanged(Editable s) {
                           p.setQuantità(finalHolder.edit.getText().toString().trim());
                            SharedPreferences states = getContext().getSharedPreferences("states", Context.MODE_PRIVATE);
                            SharedPreferences.Editor editor = states.edit();
                            editor.putString("finalHolder.edit" + finalHolder.planetName.getText().toString(), finalHolder.edit.getText().toString().trim());
                            editor.commit();
                        }
                    });

                    /*  SharedPreferences states = getContext().getSharedPreferences("states", Context.MODE_PRIVATE);
                    SharedPreferences.Editor editor = states.edit();
                    editor.putBoolean("holder.chkBox" + finalHolder.planetName.getText().toString(), true);
                    editor.commit(); */
                    //Utility.putPizzaItem(p);
                    //Utility.getPizzaItem(p);


                } else {
                    SharedPreferences states = getContext().getSharedPreferences("states", Context.MODE_PRIVATE);
                    SharedPreferences.Editor editor3 = states.edit();
                    finalHolder.edit.setVisibility(View.GONE);
                    finalHolder.edit.setEnabled(false);
                    finalHolder.edit.setText("");
                   /* editor3.putBoolean("holder.chkBox" + finalHolder.planetName.getText().toString(), false);
                    editor3.commit(); */

                }
                /* SharedPreferences states = getContext().getSharedPreferences("states", Context.MODE_PRIVATE);
                SharedPreferences.Editor editor = states.edit();
                editor.apply();*/

            }
        });
        /* holder.chkBox.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (finalHolder.chkBox.isChecked()) {
                    finalHolder.edit.setVisibility(View.VISIBLE);
                    finalHolder.edit.setEnabled(true);
                    SharedPreferences states = getContext().getSharedPreferences("states", Context.MODE_PRIVATE);
                    SharedPreferences.Editor editor = states.edit();
                    editor.putBoolean("holder.chkBox", true);
                    //pizzaSelected.put(p.getId(), p);
                    System.out.println(p.getId());
                } else {

                    finalHolder.edit.setVisibility(View.GONE);
                    finalHolder.edit.setEnabled(false);
                    finalHolder.edit.setText(null);
                    pizzaSelected.remove(p.getId());

                }

            }
        }); */


       /* finalHolder.edit.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
            }

            @Override
            public void afterTextChanged(Editable s) {
                p.setQuantità(finalHolder.edit.getText().toString().trim());
                SharedPreferences states = getContext().getSharedPreferences("states", Context.MODE_PRIVATE);
                SharedPreferences.Editor editor = states.edit();
                editor.putString("finalHolder.edit" + finalHolder.planetName.getText().toString(), finalHolder.edit.getText().toString().trim());
                editor.commit();
            }
        }); */

       // holder.planetName.setText(p.getName());
       // holder.distView.setText("" + p.getDistance());
       // holder.valuta.setText("" + p.getValuta());
       // holder.chkBox.setChecked(p.isSelected());
       // holder.chkBox.setTag(p);
       // holder.edit.setEnabled(false);
       //  holder.id.setId(p.getId());


       return row;
    }

    ArrayList<Planet> getBox() {
        ArrayList<Planet> box = new ArrayList<Planet>();
        for (Planet p : planetList) {
            if (p.isSelected())
                box.add(p);
        }
        return box;
    }

}

Fragment:

public class MyListFragment extends Fragment implements
        android.widget.CompoundButton.OnCheckedChangeListener {

    ListView lv;
    ArrayList<Planet> planetList;
    static PlanetAdapter plAdapter;

    BirraAdapter biAdapter;
    PlanetAdapter.PlanetHolder holder;
    private static Context context = null;
    private static FragmentActivity mInstance;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.fragment_list2, container, false);
        context = getActivity();
        mInstance= getActivity();
        Button mButton = (Button) rootView.findViewById(R.id.button);
        mButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                showResult(v);
            }
        });
        //return inflater.inflate(R.layout.fragment_list2, container, false);
        return rootView;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        lv = (ListView)getView().findViewById(R.id.listview);
        displayPlanetList();

    }

    private void displayPlanetList() {

        planetList = new ArrayList<Planet>();
        planetList.add(new Planet("Margherita", 6, "€",1));
        planetList.add(new Planet("Diavola", 7,"€",2));
        planetList.add(new Planet("Bufalina", 5,"€",3));
        planetList.add(new Planet("Marinara", 5, "€",4));
        planetList.add(new Planet("Viennese", 4, "€", 5));

        plAdapter = new PlanetAdapter(planetList, getContext()) {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

                int pos = lv.getPositionForView(buttonView);
                if (pos != ListView.INVALID_POSITION) {
                    Planet p = planetList.get(pos);
                    p.setSelected(isChecked);


            /*Toast.makeText(
                getActivity(),
                "Clicked on Pizza: " + p.getName() + ". State: is "
                        + isChecked, Toast.LENGTH_SHORT).show();*/
                }
            }
        };

        lv.setAdapter(plAdapter);
    }



    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

        /*int pos = lv.getPositionForView(buttonView);
        if (pos != ListView.INVALID_POSITION) {
            Planet p = planetList.get(pos);
            p.setSelected(isChecked);

            *//*Toast.makeText(
                getActivity(),
                "Clicked on Planet: " + p.getName() + ". State: is "
                        + isChecked, Toast.LENGTH_SHORT).show();*//*
        }*/

    }

/*
    public static void showResult(View v) {
        String  result = "Selected Product are :";
        int totalAmount=0;
        String  result2 = "";
        int totalAmount2=0;

        String a="";
        String z="";

        for (Planet p : plAdapter.getBox()) {
            if (p.isSelected()) {
                result2 += "\n" + p.getName()+" "+p.getDistance()+"€"+"q.tà :"+p.getQuantità();
                int quantitaInt= Integer.parseInt(p.getQuantità() );
                totalAmount2+=p.getDistance() * quantitaInt;
                //z=String.valueOf(totalAmount2);
            }
            int totale=totalAmount+totalAmount2;
            z=String.valueOf(totale);
        }

        Toast.makeText(context, result2 + "\n" + "Total Amount:=" + totalAmount2 + "€", Toast.LENGTH_LONG).show();
        //Toast.makeText(getActivity(), result2 + "\n" + "Total Amount:=" + totalAmount2 + "€", Toast.LENGTH_LONG).show();


        Bundle bun2 = new Bundle();
        bun2.putString("scelta", result2);
        ThreeFragment fgsearch2 = new ThreeFragment();
        fgsearch2.setArguments(bun2);
        android.support.v4.app.FragmentTransaction transaction2 = mInstance.getSupportFragmentManager().beginTransaction();
        transaction2.replace(R.id.content_main, fgsearch2);
        transaction2.commit();
    } */

    public static void showResult(View v) {
        String  result = "Selected Product are :";
        int totalAmount=0;
        String  result2 = "";
        int totalAmount2=0;

        String a="";
        // String z="";

        for (Planet p : plAdapter.getBox()) {
            if (p.isSelected()) {

                result += "\n" + p.getName()+" "+p.getDistance()+"€"+"q.tà :"+p.getQuantità();
                int quantitaInt= Integer.parseInt(p.getQuantità() );
                totalAmount2+=p.getDistance() * quantitaInt;
                // z=String.valueOf(totalAmount2);
            }
        }

        Toast.makeText(context, result + "\n" + "Total Amount:=" + totalAmount2 + "€", Toast.LENGTH_LONG).show();
        // Toast.makeText(getActivity(), result2 + "\n" + "Total Amount:=" + totalAmount2 + "€", Toast.LENGTH_LONG).show();


        Bundle bun2 = new Bundle();
        bun2.putString("scelta3", result);
        TwoFragment fgsearch2 = new TwoFragment();
        fgsearch2.setArguments(bun2);
        android.support.v4.app.FragmentTransaction transaction2 = mInstance.getSupportFragmentManager().beginTransaction();
        transaction2.replace(R.id.content_main3, fgsearch2);
        transaction2.commit();

        /* Bundle bun = new Bundle();
        // bun.putString("totalepizze",z);
        bun.putInt("totalepizze",totalAmount2);
        TwoFragment fgsearch = new TwoFragment();
        fgsearch.setArguments(bun);
        android.support.v4.app.FragmentTransaction transaction = mInstance.getSupportFragmentManager().beginTransaction();
        transaction.replace(R.id.content_main2, fgsearch);
        transaction.commit(); */

        /* Bundle bun = new Bundle();
        bun.putString("scelta", result2);
        TwoFragment fgsearch = new TwoFragment();
        fgsearch.setArguments(bun);
        android.support.v4.app.FragmentTransaction transaction = getActivity().getSupportFragmentManager().beginTransaction();
        transaction.replace(R.id.content_main2, fgsearch);
        transaction.commit(); */
    }

}

Activity:

public class Main extends AppCompatActivity {


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        getSupportFragmentManager().beginTransaction()
            .replace(R.id.fragmentContainer, new MyListFragment()).commit();

    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        SharedPreferences myPrefs = this.getSharedPreferences("states",
            Context.MODE_PRIVATE);
        myPrefs.edit().remove("states");
        myPrefs.edit().clear();
        myPrefs.edit().commit();
    }
}

LOGCAT:

05-22 13:40:33.781 12076-12076/? D/dalvikvm: Not late-enabling CheckJNI (already on)
05-22 13:40:34.831 12076-12081/info.androidhive.materialtabs I/dalvikvm: threadid=3: reacting to signal 3
05-22 13:40:35.190 12076-12081/info.androidhive.materialtabs I/dalvikvm: Wrote stack traces to '/data/anr/traces.txt'
05-22 13:40:35.331 12076-12081/info.androidhive.materialtabs I/dalvikvm: threadid=3: reacting to signal 3
05-22 13:40:35.411 12076-12081/info.androidhive.materialtabs I/dalvikvm: Wrote stack traces to '/data/anr/traces.txt'
05-22 13:40:35.761 12076-12081/info.androidhive.materialtabs I/dalvikvm: threadid=3: reacting to signal 3
05-22 13:40:35.810 12076-12081/info.androidhive.materialtabs I/dalvikvm: Wrote stack traces to '/data/anr/traces.txt'
05-22 13:40:35.871 12076-12076/info.androidhive.materialtabs W/dalvikvm: VFY: unable to find class referenced in signature (Landroid/view/SearchEvent;)
05-22 13:40:35.880 12076-12076/info.androidhive.materialtabs I/dalvikvm: Could not find method android.view.Window$Callback.onSearchRequested, referenced from method android.support.v7.view.WindowCallbackWrapper.onSearchRequested
05-22 13:40:35.880 12076-12076/info.androidhive.materialtabs W/dalvikvm: VFY: unable to resolve interface method 18907: Landroid/view/Window$Callback;.onSearchRequested (Landroid/view/SearchEvent;)Z
05-22 13:40:35.880 12076-12076/info.androidhive.materialtabs D/dalvikvm: VFY: replacing opcode 0x72 at 0x0002
05-22 13:40:35.890 12076-12076/info.androidhive.materialtabs I/dalvikvm: Could not find method android.view.Window$Callback.onWindowStartingActionMode, referenced from method android.support.v7.view.WindowCallbackWrapper.onWindowStartingActionMode
05-22 13:40:35.890 12076-12076/info.androidhive.materialtabs W/dalvikvm: VFY: unable to resolve interface method 18911: Landroid/view/Window$Callback;.onWindowStartingActionMode (Landroid/view/ActionMode$Callback;I)Landroid/view/ActionMode;
05-22 13:40:35.890 12076-12076/info.androidhive.materialtabs D/dalvikvm: VFY: replacing opcode 0x72 at 0x0002
05-22 13:40:36.191 12076-12076/info.androidhive.materialtabs I/dalvikvm: Could not find method android.view.ViewGroup.onRtlPropertiesChanged, referenced from method android.support.v7.widget.Toolbar.onRtlPropertiesChanged
05-22 13:40:36.221 12076-12076/info.androidhive.materialtabs W/dalvikvm: VFY: unable to resolve virtual method 18802: Landroid/view/ViewGroup;.onRtlPropertiesChanged (I)V
05-22 13:40:36.221 12076-12076/info.androidhive.materialtabs D/dalvikvm: VFY: replacing opcode 0x6f at 0x0007
05-22 13:40:36.281 12076-12081/info.androidhive.materialtabs I/dalvikvm: threadid=3: reacting to signal 3
05-22 13:40:36.351 12076-12076/info.androidhive.materialtabs I/dalvikvm: Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.widget.TintTypedArray.getChangingConfigurations
05-22 13:40:36.351 12076-12076/info.androidhive.materialtabs W/dalvikvm: VFY: unable to resolve virtual method 442: Landroid/content/res/TypedArray;.getChangingConfigurations ()I
05-22 13:40:36.351 12076-12076/info.androidhive.materialtabs D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002
05-22 13:40:36.361 12076-12076/info.androidhive.materialtabs I/dalvikvm: Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.widget.TintTypedArray.getType
05-22 13:40:36.371 12076-12076/info.androidhive.materialtabs W/dalvikvm: VFY: unable to resolve virtual method 464: Landroid/content/res/TypedArray;.getType (I)I
05-22 13:40:36.371 12076-12076/info.androidhive.materialtabs D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002
05-22 13:40:36.401 12076-12081/info.androidhive.materialtabs I/dalvikvm: Wrote stack traces to '/data/anr/traces.txt'
05-22 13:40:36.531 12076-12076/info.androidhive.materialtabs I/dalvikvm: Could not find method android.widget.LinearLayout$LayoutParams.<init>, referenced from method android.support.design.widget.AppBarLayout$LayoutParams.<init>
05-22 13:40:36.561 12076-12076/info.androidhive.materialtabs W/dalvikvm: VFY: unable to resolve direct method 19435: Landroid/widget/LinearLayout$LayoutParams;.<init> (Landroid/widget/LinearLayout$LayoutParams;)V
05-22 13:40:36.561 12076-12076/info.androidhive.materialtabs D/dalvikvm: VFY: replacing opcode 0x70 at 0x0000
05-22 13:40:36.561 12076-12076/info.androidhive.materialtabs I/dalvikvm: Could not find method android.widget.LinearLayout$LayoutParams.<init>, referenced from method android.support.design.widget.AppBarLayout$LayoutParams.<init>
05-22 13:40:36.571 12076-12076/info.androidhive.materialtabs W/dalvikvm: VFY: unable to resolve direct method 19435: Landroid/widget/LinearLayout$LayoutParams;.<init> (Landroid/widget/LinearLayout$LayoutParams;)V
05-22 13:40:36.571 12076-12076/info.androidhive.materialtabs D/dalvikvm: VFY: replacing opcode 0x70 at 0x0000
05-22 13:40:36.771 12076-12081/info.androidhive.materialtabs I/dalvikvm: threadid=3: reacting to signal 3
05-22 13:40:36.771 12076-12079/info.androidhive.materialtabs D/dalvikvm: GC_CONCURRENT freed 217K, 3% free 12838K/13127K, paused 14ms+6ms
05-22 13:40:36.841 12076-12081/info.androidhive.materialtabs I/dalvikvm: Wrote stack traces to '/data/anr/traces.txt'
05-22 13:40:36.970 12076-12076/info.androidhive.materialtabs I/dalvikvm: Could not find method android.content.res.Resources.getDrawable, referenced from method android.support.v7.widget.ResourcesWrapper.getDrawable
05-22 13:40:36.970 12076-12076/info.androidhive.materialtabs W/dalvikvm: VFY: unable to resolve virtual method 405: Landroid/content/res/Resources;.getDrawable (ILandroid/content/res/Resources$Theme;)Landroid/graphics/drawable/Drawable;
05-22 13:40:36.970 12076-12076/info.androidhive.materialtabs D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002
05-22 13:40:36.970 12076-12076/info.androidhive.materialtabs I/dalvikvm: Could not find method android.content.res.Resources.getDrawableForDensity, referenced from method android.support.v7.widget.ResourcesWrapper.getDrawableForDensity
05-22 13:40:36.980 12076-12076/info.androidhive.materialtabs W/dalvikvm: VFY: unable to resolve virtual method 407: Landroid/content/res/Resources;.getDrawableForDensity (IILandroid/content/res/Resources$Theme;)Landroid/graphics/drawable/Drawable;
05-22 13:40:36.980 12076-12076/info.androidhive.materialtabs D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002
05-22 13:40:37.261 12076-12081/info.androidhive.materialtabs I/dalvikvm: threadid=3: reacting to signal 3
05-22 13:40:37.330 12076-12081/info.androidhive.materialtabs I/dalvikvm: Wrote stack traces to '/data/anr/traces.txt'
05-22 13:40:37.671 12076-12076/info.androidhive.materialtabs W/FragmentManager: moveToState: Fragment state for TwoFragment{4160a840 #1 id=0x7f0c006b android:switcher:2131492971:1} not updated inline; expected state 3 found 2
05-22 13:40:37.701 12076-12076/info.androidhive.materialtabs W/FragmentManager: moveToState: Fragment state for ThreeFragment{41676830 #2 id=0x7f0c006b android:switcher:2131492971:2} not updated inline; expected state 3 found 2
05-22 13:40:37.711 12076-12076/info.androidhive.materialtabs W/FragmentManager: moveToState: Fragment state for FourFragment{41639f98 #3 id=0x7f0c006b android:switcher:2131492971:3} not updated inline; expected state 3 found 2
05-22 13:40:37.731 12076-12076/info.androidhive.materialtabs W/FragmentManager: moveToState: Fragment state for FiveFragment{4160d458 #4 id=0x7f0c006b android:switcher:2131492971:4} not updated inline; expected state 3 found 2
05-22 13:40:37.741 12076-12076/info.androidhive.materialtabs W/FragmentManager: moveToState: Fragment state for SixFragment{4164fde0 #5 id=0x7f0c006b android:switcher:2131492971:5} not updated inline; expected state 3 found 2
05-22 13:40:37.771 12076-12081/info.androidhive.materialtabs I/dalvikvm: threadid=3: reacting to signal 3
05-22 13:40:37.811 12076-12076/info.androidhive.materialtabs W/FragmentManager: moveToState: Fragment state for SevenFragment{41660860 #6 id=0x7f0c006b android:switcher:2131492971:6} not updated inline; expected state 3 found 2
05-22 13:40:37.832 12076-12081/info.androidhive.materialtabs I/dalvikvm: Wrote stack traces to '/data/anr/traces.txt'
05-22 13:40:37.861 12076-12076/info.androidhive.materialtabs W/FragmentManager: moveToState: Fragment state for EightFragment{41654958 #7 id=0x7f0c006b android:switcher:2131492971:7} not updated inline; expected state 3 found 2
05-22 13:40:37.891 12076-12076/info.androidhive.materialtabs W/FragmentManager: moveToState: Fragment state for NineFragment{41643a90 #8 id=0x7f0c006b android:switcher:2131492971:8} not updated inline; expected state 3 found 2
05-22 13:40:37.911 12076-12076/info.androidhive.materialtabs W/FragmentManager: moveToState: Fragment state for TenFragment{41614fa8 #9 id=0x7f0c006b android:switcher:2131492971:9} not updated inline; expected state 3 found 2
05-22 13:40:38.270 12076-12081/info.androidhive.materialtabs I/dalvikvm: threadid=3: reacting to signal 3
05-22 13:40:38.331 12076-12081/info.androidhive.materialtabs I/dalvikvm: Wrote stack traces to '/data/anr/traces.txt'
05-22 13:40:38.481 12076-12076/info.androidhive.materialtabs I/System.out: true
05-22 13:40:38.641 12076-12079/info.androidhive.materialtabs D/dalvikvm: GC_CONCURRENT freed 139K, 2% free 13161K/13383K, paused 6ms+6ms
05-22 13:40:38.781 12076-12081/info.androidhive.materialtabs I/dalvikvm: threadid=3: reacting to signal 3
05-22 13:40:38.861 12076-12076/info.androidhive.materialtabs I/System.out: true
05-22 13:40:38.871 12076-12081/info.androidhive.materialtabs I/dalvikvm: Wrote stack traces to '/data/anr/traces.txt'
05-22 13:40:39.010 12076-12076/info.androidhive.materialtabs I/System.out: true
05-22 13:40:39.100 12076-12076/info.androidhive.materialtabs I/System.out: true
05-22 13:40:39.171 12076-12076/info.androidhive.materialtabs I/System.out: true
05-22 13:40:39.290 12076-12081/info.androidhive.materialtabs I/dalvikvm: threadid=3: reacting to signal 3
05-22 13:40:39.311 12076-12081/info.androidhive.materialtabs I/dalvikvm: Wrote stack traces to '/data/anr/traces.txt'
05-22 13:40:39.771 12076-12081/info.androidhive.materialtabs I/dalvikvm: threadid=3: reacting to signal 3
05-22 13:40:39.811 12076-12081/info.androidhive.materialtabs I/dalvikvm: Wrote stack traces to '/data/anr/traces.txt'
05-22 13:40:40.150 12076-12076/info.androidhive.materialtabs D/gralloc_goldfish: Emulator without GPU emulation detected.
05-22 13:40:40.280 12076-12081/info.androidhive.materialtabs I/dalvikvm: threadid=3: reacting to signal 3
05-22 13:40:40.311 12076-12081/info.androidhive.materialtabs I/dalvikvm: Wrote stack traces to '/data/anr/traces.txt'
解决方案

onDestroy is not guaranteed to be called. Most of time it can be called if operating systems wants to shut down your application.

You can use onBackPressed or onPause instead

这篇关于方法onDestroy()不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 21:44