0
我有這段代碼在Activity中打開片段。我想要做的就是調用名爲「book」的片段。如何從活動中開始片段活動從待處理的意圖與變量
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();
}
}
}
但是,束始終爲空。這裏有什麼問題? 謝謝
它沒有按」 t工作,捆綁仍然是空:( –
@SugiAlmantara什麼捆綁包?沒有捆綁了。只有一個字符串內部意圖對象 –
我的意思是'getIntent()。getStringExtra(「FragmentBooking」)!= null'仍然爲null Im sorry –