2017-04-26 67 views
1

我試圖在對話框消失後顯示新的活動。一切工作正常,但我不知道如何去對話框活動,而不重新設置活動。對話框關閉後顯示活動,無需重新設置

我有這樣的事情

Intent intent = new Intent(getActivity(), MainActivity.class); 
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK); 
    startActivity(intent); 
    getActivity().finish(); 

但這只是重置在MainActivity。任何人都可以幫助解釋我如何在不重置MainActivity上的信息的情況下展示我的MainActivity?

回答

1

無需再次開始活動,只需dismiss the dialog

dialog.dismiss(); 

或者從對話框類本身,只需調用​​。

+0

我解散了對話框,並顯示了我的MainActivity,但是FLAGS正在重設視圖。我有2個片段,片段1是我的MainActivity,片段2是我稱之爲對話框的地方。當對話框消失時,我想顯示片段1,但沒有重置。 – user993074

+0

它不與對話框本身連接。基本上你需要perfrom ['popBackStack()'](https://developer.android.com/reference/android/app/FragmentManager.html#popBackStack())。 – azizbekian

+0

我正在嘗試做這樣的事情,但仍然無法正常工作。 FragmentTransaction fragmentTransaction = getActivity()。getSupportFragmentManager() .beginTransaction(); fragmentTransaction.addToBackStack(null); fragmentTransaction.replace(R.id.main_top_fragment,new MainScreenFragment()); fragmentTransaction.commit(); – user993074