当我回到上一个片段时,它所来自的片段会留在后台,为什么?
@Override
public void onClick(View v) {
if (v == rateknap) {
AlertDialog alert = new AlertDialog.Builder(getActivity())
.setMessage("Vil du give " + ratingBar.getRating() + " stjerner?")
.setPositiveButton("Ja", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Liste.currentForslag.rate(ratingBar.getRating());
Db.setDBForslag();
launchintent();
}
}
)
.setNegativeButton("Nej", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
}
).show();
}
}
private void launchintent() {
if(getFragmentManager().getBackStackEntryCount() > 0){
getFragmentManager().popBackStack();
} else{
getActivity().finish();
}
}
编辑:
这是我想回到的片段
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
Liste.currentForslag = (Forslag)adapterView.getItemAtPosition(i);
Fragment fragment = new ForslagbeskrivelseFrag();
getFragmentManager().beginTransaction()
.replace(R.id.fragment, fragment)
//.addToBackStack(null)
.commit();
}
这是我删除的片段:
if(v == rateknap){
Fragment fragment = new RateFrag();
getFragmentManager().beginTransaction()
.replace(R.id.fragment, fragment)
.remove(ForslagbeskrivelseFrag.this)
.commit();
}
答案 0 :(得分:0)
这可能是因为当您提交片段事务时,您将其添加到backstack。删除添加到后台堆栈并再次检查。