以下是我的代码,其中getSupportFragmentManger()在Service类中无法正常工作
Fragment fragment = new OfferNotificationFragment();
FragmentManager fm = getSupportFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
fragment = fm.findFragmentByTag("tag6");
if (fragment == null) { // not added
fragment = new OfferNotificationFragment();//add fragment
ft.replace(R.id.coordinate_layout, fragment, "tag6");
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
} else { // already added
ft.remove(fragment);
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_CLOSE);
}
ft.commit();