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

            Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

            Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript