Luca
Luca

Reputation: 833

Know which menu resource is inflated

Im my application I inflate different menu resources, like this:

public boolean onCreateOptionsMenu(Menu menu) {
    _menu = menu;
    if (/* CONDITION */) {
        getMenuInflater().inflate(R.menu.menu_activity_detail, _menu);
    } else {
        getMenuInflater().inflate(R.menu.menu_empty, _menu);
    }
    return true;
}

before this I save the Menu object for further reuse, like inflating a new menu under specific circumstances.

Now the question: is there any way to know which resource I've inflated at the creation of my activity, without manually saving the id of R.menu.menu_res?

Upvotes: 0

Views: 248

Answers (1)

Mimmo Grottoli
Mimmo Grottoli

Reputation: 5773

You should not keep a reference to the menu. Why don't you use the invalidateOptionsMenu() method of your Activity? There's the supportInvalidateOptionsMenu() to handle AppCompatActivity

Upvotes: 1

Related Questions