Android Menu duplication fixed with clear but it clears the parent activity menuHow do save an Android Activity state using save instance state?Activity restart on rotation AndroidStrange out of memory issue while loading an image to a Bitmap objectFling gesture detection on grid layoutViewPager and fragments — what's the right way to store fragment's state?Android Options Menu in FragmentBest practice for instantiating a new Android FragmentHow to manage startActivityForResult on Android?Dilemma: when to use Fragments vs Activities:You need to use a Theme.AppCompat theme (or descendant) with this activity

Historically, were women trained for obligatory wars? Or did they serve some other military function?

Packet sniffer for MacOS Mojave and above

How to scale a verbatim environment on a minipage?

Airbnb - host wants to reduce rooms, can we get refund?

How to creep the reader out with what seems like a normal person?

Entropy as a function of temperature: is temperature well defined?

Can I use 1000v rectifier diodes instead of 600v rectifier diodes?

Pressure to defend the relevance of one's area of mathematics

How could a planet have most of its water in the atmosphere?

Unidentified items in bicycle tube repair kit

A non-technological, repeating, phenomenon in the sky, holding its position in the sky for hours

Hang 20lb projector screen on Hardieplank

Visa for volunteering in England

How to efficiently calculate prefix sum of frequencies of characters in a string?

Does hiding behind 5-ft-wide cover give full cover?

Can a cyclic Amine form an Amide?

Is lying to get "gardening leave" fraud?

What happened to Ghost?

How can I close a gap between my fence and my neighbor's that's on his side of the property line?

My ID is expired, can I fly to the Bahamas with my passport

Why do freehub and cassette have only one position that matches?

Transfer over $10k

Does the Darkness spell dispel the Color Spray and Flaming Sphere spells?

Binary Numbers Magic Trick



Android Menu duplication fixed with clear but it clears the parent activity menu


How do save an Android Activity state using save instance state?Activity restart on rotation AndroidStrange out of memory issue while loading an image to a Bitmap objectFling gesture detection on grid layoutViewPager and fragments — what's the right way to store fragment's state?Android Options Menu in FragmentBest practice for instantiating a new Android FragmentHow to manage startActivityForResult on Android?Dilemma: when to use Fragments vs Activities:You need to use a Theme.AppCompat theme (or descendant) with this activity






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I have created different fragment and populated some menu based on the fragment. I was getting duplicate menu items so I used clear as suggested various stackoveflow posts but the problem is when I use clear in fragment it also clears the main activity menu items.










share|improve this question






















  • Did you fix it? Where was the problem?

    – Andrew Churilo
    Apr 4 at 8:14

















0















I have created different fragment and populated some menu based on the fragment. I was getting duplicate menu items so I used clear as suggested various stackoveflow posts but the problem is when I use clear in fragment it also clears the main activity menu items.










share|improve this question






















  • Did you fix it? Where was the problem?

    – Andrew Churilo
    Apr 4 at 8:14













0












0








0








I have created different fragment and populated some menu based on the fragment. I was getting duplicate menu items so I used clear as suggested various stackoveflow posts but the problem is when I use clear in fragment it also clears the main activity menu items.










share|improve this question














I have created different fragment and populated some menu based on the fragment. I was getting duplicate menu items so I used clear as suggested various stackoveflow posts but the problem is when I use clear in fragment it also clears the main activity menu items.







android menu duplicates






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 22 at 20:03









GreyfrogGreyfrog

142210




142210












  • Did you fix it? Where was the problem?

    – Andrew Churilo
    Apr 4 at 8:14

















  • Did you fix it? Where was the problem?

    – Andrew Churilo
    Apr 4 at 8:14
















Did you fix it? Where was the problem?

– Andrew Churilo
Apr 4 at 8:14





Did you fix it? Where was the problem?

– Andrew Churilo
Apr 4 at 8:14












2 Answers
2






active

oldest

votes


















0














Activity and all fragments inside it use the same Menu instance. So no matter where you call clear() method, all items will be deleted.



Menu items that are used across all child fragments should be created inside Activity. Fragment-specific options should be created inside corresponding fragment. Ideally you should not have duplicated menu items. If two fragments have same menu item but third doesn't -- prefer create menu item inside every fragment but not single menu item inside activity. With this approach you will not get duplicates.




But If you want just to delete duplicates you can use menu.removeItem(itemId) method. Also you can hide redundant item with menuItem.setVisible(false).






share|improve this answer























  • Hey Andrew thanks :) Yes, i have created common menu in Main activity which is shared across Fragment. The menu I was getting duplicated are from Fragments. When I switch between Fragments, I get duplicated menu and those menu items are non reactive. So I have applied menu.clear() in main activity OnCreteOptionMenu() but I am still getting the dupilcate menu when I switch between fragments.

    – Greyfrog
    Mar 23 at 3:48



















0















When I switch between Fragments, I get duplicated menu




Maybe you have two active fragments at the same time. It can be when you use add method instead replace.






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55307069%2fandroid-menu-duplication-fixed-with-clear-but-it-clears-the-parent-activity-menu%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Activity and all fragments inside it use the same Menu instance. So no matter where you call clear() method, all items will be deleted.



    Menu items that are used across all child fragments should be created inside Activity. Fragment-specific options should be created inside corresponding fragment. Ideally you should not have duplicated menu items. If two fragments have same menu item but third doesn't -- prefer create menu item inside every fragment but not single menu item inside activity. With this approach you will not get duplicates.




    But If you want just to delete duplicates you can use menu.removeItem(itemId) method. Also you can hide redundant item with menuItem.setVisible(false).






    share|improve this answer























    • Hey Andrew thanks :) Yes, i have created common menu in Main activity which is shared across Fragment. The menu I was getting duplicated are from Fragments. When I switch between Fragments, I get duplicated menu and those menu items are non reactive. So I have applied menu.clear() in main activity OnCreteOptionMenu() but I am still getting the dupilcate menu when I switch between fragments.

      – Greyfrog
      Mar 23 at 3:48
















    0














    Activity and all fragments inside it use the same Menu instance. So no matter where you call clear() method, all items will be deleted.



    Menu items that are used across all child fragments should be created inside Activity. Fragment-specific options should be created inside corresponding fragment. Ideally you should not have duplicated menu items. If two fragments have same menu item but third doesn't -- prefer create menu item inside every fragment but not single menu item inside activity. With this approach you will not get duplicates.




    But If you want just to delete duplicates you can use menu.removeItem(itemId) method. Also you can hide redundant item with menuItem.setVisible(false).






    share|improve this answer























    • Hey Andrew thanks :) Yes, i have created common menu in Main activity which is shared across Fragment. The menu I was getting duplicated are from Fragments. When I switch between Fragments, I get duplicated menu and those menu items are non reactive. So I have applied menu.clear() in main activity OnCreteOptionMenu() but I am still getting the dupilcate menu when I switch between fragments.

      – Greyfrog
      Mar 23 at 3:48














    0












    0








    0







    Activity and all fragments inside it use the same Menu instance. So no matter where you call clear() method, all items will be deleted.



    Menu items that are used across all child fragments should be created inside Activity. Fragment-specific options should be created inside corresponding fragment. Ideally you should not have duplicated menu items. If two fragments have same menu item but third doesn't -- prefer create menu item inside every fragment but not single menu item inside activity. With this approach you will not get duplicates.




    But If you want just to delete duplicates you can use menu.removeItem(itemId) method. Also you can hide redundant item with menuItem.setVisible(false).






    share|improve this answer













    Activity and all fragments inside it use the same Menu instance. So no matter where you call clear() method, all items will be deleted.



    Menu items that are used across all child fragments should be created inside Activity. Fragment-specific options should be created inside corresponding fragment. Ideally you should not have duplicated menu items. If two fragments have same menu item but third doesn't -- prefer create menu item inside every fragment but not single menu item inside activity. With this approach you will not get duplicates.




    But If you want just to delete duplicates you can use menu.removeItem(itemId) method. Also you can hide redundant item with menuItem.setVisible(false).







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Mar 22 at 21:25









    Andrew ChuriloAndrew Churilo

    1,469815




    1,469815












    • Hey Andrew thanks :) Yes, i have created common menu in Main activity which is shared across Fragment. The menu I was getting duplicated are from Fragments. When I switch between Fragments, I get duplicated menu and those menu items are non reactive. So I have applied menu.clear() in main activity OnCreteOptionMenu() but I am still getting the dupilcate menu when I switch between fragments.

      – Greyfrog
      Mar 23 at 3:48


















    • Hey Andrew thanks :) Yes, i have created common menu in Main activity which is shared across Fragment. The menu I was getting duplicated are from Fragments. When I switch between Fragments, I get duplicated menu and those menu items are non reactive. So I have applied menu.clear() in main activity OnCreteOptionMenu() but I am still getting the dupilcate menu when I switch between fragments.

      – Greyfrog
      Mar 23 at 3:48

















    Hey Andrew thanks :) Yes, i have created common menu in Main activity which is shared across Fragment. The menu I was getting duplicated are from Fragments. When I switch between Fragments, I get duplicated menu and those menu items are non reactive. So I have applied menu.clear() in main activity OnCreteOptionMenu() but I am still getting the dupilcate menu when I switch between fragments.

    – Greyfrog
    Mar 23 at 3:48






    Hey Andrew thanks :) Yes, i have created common menu in Main activity which is shared across Fragment. The menu I was getting duplicated are from Fragments. When I switch between Fragments, I get duplicated menu and those menu items are non reactive. So I have applied menu.clear() in main activity OnCreteOptionMenu() but I am still getting the dupilcate menu when I switch between fragments.

    – Greyfrog
    Mar 23 at 3:48














    0















    When I switch between Fragments, I get duplicated menu




    Maybe you have two active fragments at the same time. It can be when you use add method instead replace.






    share|improve this answer



























      0















      When I switch between Fragments, I get duplicated menu




      Maybe you have two active fragments at the same time. It can be when you use add method instead replace.






      share|improve this answer

























        0












        0








        0








        When I switch between Fragments, I get duplicated menu




        Maybe you have two active fragments at the same time. It can be when you use add method instead replace.






        share|improve this answer














        When I switch between Fragments, I get duplicated menu




        Maybe you have two active fragments at the same time. It can be when you use add method instead replace.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 23 at 5:55









        Andrew ChuriloAndrew Churilo

        1,469815




        1,469815



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55307069%2fandroid-menu-duplication-fixed-with-clear-but-it-clears-the-parent-activity-menu%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현