X
X
xne712472015-02-15 22:28:43
Android
xne71247, 2015-02-15 22:28:43

ManagedQuery is deprecated, how to replace or what to do?

I am reading a book on android and there is an example described as follows:

Данный пример немного надуманный. Android уже содержит Фильтр на-мерений для выбора контакта из списка, который может предоставлять 
URI вида content://contacts/people/ внутри неявного Намерения. Цель 
этого учебного проекта состоит в демонстрации общих принципов, даже 
если пользы от этой конкретной реализации немного.

And the code of this small application is given, where managedQuery is called in onCreate , but androidstudio swears, says that managedQuery is outdated. How to solve this problem? Here is the code where it all happens:
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Intent intent = getIntent();
        String dataPath = intent.getData().toString();

        final Uri data = Uri.parse(dataPath + "people/");
        final Cursor c = managedQuery(data, null, null, null);
    }

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
nonrblGyN4ik, 2015-02-15
@nonrblGyN4ik

Use context.getContentResolver().query(...)
For the future, there is official documentation for such questions (or google for "managedQuery deprecated", 1 link)

M
Max, 2015-02-17
@mbelskiy

NonrblGyN4ik 's solution is not entirely correct, since the request to the database should not be executed on the ui thread.
Look this way.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question