Because getSupportLoaderManager cannot be used

Note that the Loader Manager was deprecated while touching AsyncTask. To be honest, I don't know, but I will output it for the time being.


If you do the following, Android Studio will get angry.

MainActivity.java


private LoaderManager manager;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

manager = getSupportLoaderManager();//← Not recommended



It will be struck through with ~~ getSupportLoaderManager () ~~.

That doesn't mean it doesn't work. It will move. But I was a little worried, so I read the official documentation.

LoaderManager

There seem to be two ways.

  1. Use getInstance ().
  2. Use initLoader ().

1 is just that. I want an instance, so get it.

Gets a LoaderManager associated with the given owner, such as a FragmentActivity or Fragment.

... apparently ...

2, is that you start Loader.

If the loader doesn't already exist, one is created and (if the activity/fragment is currently started) starts the loader. Otherwise the last created loader is re-used.

If it doesn't exist, it will be made, and if it already exists, it will be reused. You can also see that LoaderManager is assigned to one of Activity and Fragment.


However, in the first place

Your activity must derive from FragmentActivity to use this.

So, it means that you should inherit FragmentActivity, but The question of what to do if you want to use it elsewhere remains unanswered.

Recommended Posts

Because getSupportLoaderManager cannot be used
CentOS7 VirtualBOX yum cannot be used
[PHP] Solved "mb_strpos cannot be used"
[Rails 6] method :: delete cannot be used with link_to
Why Java String typeclass comparison (==) cannot be used
Systemctl cannot be used on Ubuntu inside Docker container
Java Stream cannot be reused.
Note that system properties including JAXBContext cannot be used in Java11
The org.junit.jupiter.api package cannot be found.
Spring-security error message cannot be changed
Measures when model cannot be created
[Rails 6] MySQL 2 cannot be bundle install
Java cannot be installed on Ubuntu 13.04
Android Studio JRE cannot be changed
Java code that cannot be used from Kotlin (for in-house study sessions)
[Java] Variables declared inside the `for statement` cannot be used outside the` for statement block`