Question

I have 2 activities (see picture below).

Activity 1 has ListFragment with list of items filled by CursorLoader. Activity 2 has ActionBar Tabs with ListFragments containing detailed info (also filled by CursorLoader).

Number of tabs I have to read from the first table, it's a item's attribute. What is the best practice to do this? (When? and How?)

When?

  1. OnListItemClick() in the Activity 1 before starting Activity 2
  2. OnCreate() in the Activity 2

If I get this value in OnListItemClick - it will look like slow reaction on user's action, because Activity 2 will be started is onLoaderFinished() after database answer.

My ListFragments implement LoaderManager.LoaderCallbacks. If I get number of tabs in onCreate() - I should implement LoaderManager.LoaderCallbacks also for Activity 2. Wouldn't it bee too overwhelming with Loaders?

HOW?

CursorLoader? Is it a good practice to get one single value with CursorLoader?

Description

Was it helpful?

Solution

As usual, no help, my own answer!

I've used getContentResolver().query(baseUri, PROJECTION1, null, null, null); in onCreate() of second activity

OTHER TIPS

I had a similar issue and it seems to be a good practice to implement LoaderManager.LoaderCallbacks in the second Activity. It adds a little bit of extra code, but like this you guarantee that the query will always be managed on its own thread. In addition, it frees you from handling the cursor together with the Activity lifecycle.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top