Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setHasOptionsMenu is deprecated #173

Open
kandrio opened this issue Sep 26, 2023 · 1 comment
Open

setHasOptionsMenu is deprecated #173

kandrio opened this issue Sep 26, 2023 · 1 comment

Comments

@kandrio
Copy link
Contributor

kandrio commented Sep 26, 2023

Overview

This is part of #161.

In a number of Fragments in the superapp, we use setHasOptionsMenu in order to declare that a given Fragment would like to participate in populating the options menu by receiving a call to onCreateOptionsMenu. However, the setHasOptionsMenu API is deprecated and its use produces a number of deprecation warnings when we build the superapp. Therefore, in an effort to clean the superapp from deprecation warnings, we want to replace this API with its modern counterpart.

Recommended Actions

The Android Developer documentation proposes that we use the addMenuProvider() API instead. This API function a member function of ComponentActivity. Here is the relevant code example that shows an example of how to use that API:

The Problem

The addMenuProvider() API was introduced in version 1.4.0 of AndroidX Activity. In order to declare that version, I guessed that I should add the following line to the build.gradle of each module (e.g: debug, musicdao etc...):

  • implementation 'androidx.activity:activity:1.4.0'.

But that doesn't correctly upgrade ComponentActivity so that it implements the addMenuProvider() function that we need. Let's take the debug module for example to show what's going on.

  1. As you can see here, the DebugActivity inherits from the BaseActivity
  2. As you can see here, the BaseActivity inherits from the AndroidX AppCompatActivity.
  3. Through a series of inheritances (AppCompatActivity -> FragmentActivity -> ComponentActivity), we derive that DebugActivity inherits from ComponentActivity, therefore we should be able to use the desired addMenuProvider() member function of ComponentActivity.

However, when I trace back the code, I see that we're still using an outdated version of activity (version 1.2.0 instead of the desired 1.4.0) and I can't seem to update it through the build.gradle file.

@InvictusRMC Any ideas?

CC @synctext

@kandrio
Copy link
Contributor Author

kandrio commented Sep 29, 2023

Update

I just found out that the latest version of the androidx.appcompat:appcompat dependency that contains the AppCompatActivity that we're using depends on androidx.activity:activity:1.1.0 which is lower than 1.4.0 where the new API was introduced. So, it seems that if we want to get rid of this deprecation warning, we must use a different Activity than AppCompatActivity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant