1 回答

TA貢獻(xiàn)1777條經(jīng)驗(yàn) 獲得超3個(gè)贊
public static在你的MainActivity.
public static int FRAGMENT_TO_BE_LOADED = 0;
現(xiàn)在從 中SlideActivity,將變量設(shè)置為一個(gè)數(shù)字(例如 3,即當(dāng)您返回到您的MainActivity.
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
if (id == R.id.nav_home) {
MainActivity.FRAGMENT_TO_BE_LOADED = 3;
finish();
}
}
現(xiàn)在在你的 中MainActivity,你需要有一個(gè)onResume函數(shù)來檢查變量并相應(yīng)地加載片段。
@Override
protected void onResume() {
super.onResume();
if(FRAGMENT_TO_BE_LOADED == 1) loadFragment1();
else if(FRAGMENT_TO_BE_LOADED == 2) loadFragment2();
else if(FRAGMENT_TO_BE_LOADED == 3) loadFragment3();
}
希望能解決您的問題。
添加回答
舉報(bào)