我使用的意圖是這樣開始的活動:在單擊後退按鈕活動正在重新啓動本身
Bundle bundle = new Bundle();
bundle.putParcelableArrayList("datacover",arrayList);
Intent intent = new Intent(TroubleShootActivity.this,SearchResultsActivity.class);
intent.putExtra("bundle",bundle);
startActivity(intent);
我不是整理活動,但仍當我在一個活動上單擊後退按鈕,它不返回到以前的活動,而是重新啓動自己。
代碼的其他活動:下面的代碼
public class SearchResultsActivity extends AppCompatActivity implements InnerDetailsFragment.OntroubleshootinneritemsListener,InnerDetailsFragment.OnHandleBack,CompleteDetailsFragment.OnHandleBack {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_search_results);
if(!getResources().getBoolean(R.bool.twoPaneMode)){
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}else{
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
Bundle bundle=getIntent().getBundleExtra("bundle");
FragmentManager fragmentManager = getSupportFragmentManager();
Fragment Inner = new InnerDetailsFragment();
bundle.putString("val", "search");
Inner.setArguments(bundle);
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction().replace(R.id.activity_search_results,Inner);
fragmentTransaction.commit();
}
@Override
public void onBackClick(String inner) {
super.onBackPressed();
}
@Override
public void ontroubleinneritemelected(int position, String heading, CoverageData coverageData) {
Bundle bundle = new Bundle();
bundle.putParcelable("coverage",coverageData);
FragmentManager fragmentManager = getSupportFragmentManager();
Fragment Detailsf= new CompleteDetailsFragment();
Detailsf.setArguments(bundle);
FragmentTransaction ft = fragmentManager.beginTransaction().replace(R.id.activity_search_results,Detailsf);
ft.addToBackStack("completedetails");
ft.commit();
}
@Override
public void onBackPressed() {
super.onBackPressed();
}
}
使用finish()代替super.onBackPressed(); –
你能分享InnerDetailsFragment嗎?或者這3個聽衆。 – JavadKhan
根本不覆蓋後退按鈕。不知道你從中獲得什麼 – Doomsknight