【发布时间】:2017-05-03 18:22:11
【问题描述】:
我有这段代码可以在 Activity 中打开片段。我想要做的是调用一个名为“书”的片段。
Intent intent = new Intent(this, Dashboard_Admin.class);
intent.setAction(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.putExtra("FragmentBooking", "book");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this,0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
在一个片段的活动中我有这个代码
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_dashboard_admin);
Bundle extra = getIntent().getExtras();
Toast.makeText(this, "test!!!!!!!!!!!!!!!!!!!!", Toast.LENGTH_SHORT).show();
if (extra!=null){
String idFrg = extra.getString("FragmentBooking");
Toast.makeText(this, "Hello: "+idFrg, Toast.LENGTH_SHORT).show();
if (idFrg.equals("book")){
Log.d(TAG_SUCCESS, "Test");
Fragment fragment = null;
Class fragmentClass = null;
fragmentClass = FragmentBookingKendaraan.class;
try {
fragment = (Fragment) fragmentClass.newInstance();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction().replace(R.id.flContentAdmin, fragment).commit();
}
}
}
但是,捆绑始终为空。这里有什么问题? 谢谢
【问题讨论】:
标签: android android-fragments android-notifications android-pendingintent