android - do you ever have to add fragments to the manifest

后端 未结 2 872
清歌不尽
清歌不尽 2021-02-07 01:48

Im using a fragment that is supposed to display a webview. When I try to instantiate it from the class that uses it I get the following warning in my logcat.

02-         


        
相关标签:
2条回答
  • 2021-02-07 02:27

    if you want to go back from activity to Fragment try this

    proToolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
    

    //Note: you must give an id to the Main layout of your activity e.g : searchVehicles

                ((ConstraintLayout) findViewById(R.id.searchVehicles)).removeAllViews();
                FragmentManager fragmentManager = getSupportFragmentManager();
                FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
                fragment_nearby_vehicles fnv = new fragment_nearby_vehicles();
                fragmentTransaction.add(R.id.searchVehicles, fnv).commit();
            }
        });
    
    0 讨论(0)
  • 2021-02-07 02:34

    No don't add it to your manifest. You never need to add fragments to your manifest.

    Do you create an Intent somewhere to start the WebActivity? How is it brought to the screen, that is probably where your problem lies.

    EDIT

    This is your problem:

     Intent showContent = new Intent(getApplicationContext(),
                WebFrag.class);
     startActivity(showContent);
    

    You can't start a Fragment as an Activity, you'll have to wrap the fragment in an Activity that extends FragmentActivity

    0 讨论(0)
提交回复
热议问题