开发者

How to use the managed query efficiently in Android?

I was trying to use the managedquery() in android to get back a cursor when working with a content provider. I used this because it was mentioned that this will handle the closing of the cursor by itself when the activity is paused or resumed.

But however this works on the Activity class only. But I have more than one background threads using the asynctask in android. I do a same fetch of list in more than one thread. So its repetitive code. This is because i cant call a function of one thread class from other thread dobackground(). Is there a easy and safe way to avoid this repetitive code. Kindly advice. Thank you for your hel开发者_如何学编程p and time.


Can't you have an abstract asynctask class which implements this db query code (if that's all you're doing in the background thread, then put it in doInBackground(), otherwise put it in a private method), and then have your concrete child classes which extend this abstract class call super.doInBackground or call that private method?

E.G.

private abstract AbstractQueryTask extends AsyncTask<Long, Void, Long> {

protected Cursor querycode{
//put your query code here
}

}

public ConcreteQueryTask extends AbstractQueryTask {

//put the doInBackground and onPostExecute implementations here

}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜