首页 > 解决方案 > 不推荐使用 getSupportLoadManager()

问题描述

public void onSwiped(RecyclerView.ViewHolder viewHolder, int swipeDir) {

                int id = (int) viewHolder.itemView.getTag();

                String stringId = Integer.toString(id);
                Uri uri = TaskContract.TaskEntry.CONTENT_URI;
                uri = uri.buildUpon().appendPath(stringId).build();

                getContentResolver().delete(uri, null, null);

                getSupportLoaderManager().restartLoader(TASK_LOADER_ID, null, MainActivity.this);

            }
        }).attachToRecyclerView(mRecyclerView);

        FloatingActionButton fabButton = findViewById(R.id.fab);

        fabButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                Intent addTaskIntent = new Intent(MainActivity.this, AddTaskActivity.class);
                startActivity(addTaskIntent);
            }
        });

        getSupportLoaderManager().initLoader(TASK_LOADER_ID, null, this);
    }

    @Override
    protected void onResume() {
        super.onResume();

        getSupportLoaderManager().restartLoader(TASK_LOADER_ID, null, this);
    }

getSupportLoadManager()已弃用。任何遇到该错误的人我都会真正使用一些帮助。

标签: javaandroid

解决方案


从 Android P (API 28) 开始,Loaders 已被弃用,如Loaders中所写。您应该将 更改getSupportLoaderManager()LoaderManager.getInstance(T)

LoaderManager是框架的 LoaderManager 的静态库支持版本。


推荐阅读