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;
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
add a comment |
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
Did you fix it? Where was the problem?
– Andrew Churilo
Apr 4 at 8:14
add a comment |
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
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
android menu duplicates
asked Mar 22 at 20:03
GreyfrogGreyfrog
142210
142210
Did you fix it? Where was the problem?
– Andrew Churilo
Apr 4 at 8:14
add a comment |
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
add a comment |
2 Answers
2
active
oldest
votes
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)
.
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
add a comment |
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
.
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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)
.
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
add a comment |
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)
.
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
add a comment |
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)
.
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)
.
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
add a comment |
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
add a comment |
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
.
add a comment |
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
.
add a comment |
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
.
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
.
answered Mar 23 at 5:55
Andrew ChuriloAndrew Churilo
1,469815
1,469815
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
Did you fix it? Where was the problem?
– Andrew Churilo
Apr 4 at 8:14