我正在尝试从主要活动中启动片段,但是每当我尝试启动该片段时,它只会将片段上的内容覆盖在主要活动上。 这是mainActivity.java
if(passwordEntered.equals(true)&& userNameEntered.equals(true))
{
if(passwordString.equals("theadmin")&&usernameString.equals("admin"))
{
Intent adminIntent=new Intent(MainActivity.this,EmptyActivity.class);
startActivity(adminIntent);
}
}
这是adminpage.java,但它应该运行它的homefragment,但是它覆盖了mainActivity
public static FragmentManager fragmentManager;
public static MyAppDatabase myAppDatabase;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
fragmentManager=getSupportFragmentManager();
myAppDatabase= Room.databaseBuilder(getApplicationContext(),MyAppDatabase.class,"userSdb").allowMainThreadQueries().build();
if(findViewById(R.id.fragmentContainer)!=null)
{
if(savedInstanceState!=null)
{
return;
}
fragmentManager.beginTransaction().add(R.id.fragmentContainer,new HomeFragment()).commit();
}
}