Office Hours — Today, April 8

Yesterday, April 7

Apr 8
9:50 AM
Mark M.
has entered the room
9:55 AM
Mark M.
turned on guest access
Andrei
has entered the room
Andrei
Hi Mark
10:00 AM
Mark M.
hello, Andrei!
10:00 AM
Mark M.
how can I help you today?
Andrei
I have a few questions, all revolving around a context with multiple fragments
I have a LinearLayout with two fragments, one with a list of items and the other one with details about the item currently selected in the first fragment. The first fragment is embedded statically in the layout, whereas the other one dynamically via a FrameLayout. Each fragment has its own loader as they interrogate different tables. When adding another item, I launch a third fragment which replaces the LinearLayout. When finishing adding a new item, I do a "getFragmentManager().popBackStack()" to get back to the previous layout with two fragments. However, the new item does not appear in the item list from the first fragment. I know the loaders do some caching. If this is the problem, how can I force a refresh?
"When adding another item" = "When adding another item to the 1st framgent's list of items"
Mark M.
how are you "adding a new item"? are you calling insert() on a ContentResolver or something?
Andrei
I call insert on a dbHelper, I don't need a ContentResolver
Mark M.
ummm... what sort of Loader are you using, then?
Andrei
your loaderex :-)
Mark M.
oh
Andrei
I use SqlCipher
Mark M.
then you should be calling insert() on the loader
so the loader knows to reload its Cursor for the UI
Andrei
that means that I should return the data to the 1st fragment and that one should use the loader to insert the data
Mark M.
not necessarily
Andrei
I don't have access to the loader in the 3rd fragment currently
Mark M.
and that's one of the reasons why I have discontinued this library
10:05 AM
Mark M.
in short, loaders suck *except* for CursorLoader and a ContentProvider
so, if you wish to continue using SQLCipherCursorLoader, you would need to either get the Loader someplace where all fragments in the activity can reach it, or you would need to pass the data to be inserted to the first fragment, so it can do the insert
Andrei
Ok, I'll read that. I know you wanted to discontinue that. I imagine it's also a headache to answer all people who use loaderex...
Mark M.
it's more that it just doesn't work very well in practice
so I never use it
so I don't maintain it
Luca
has entered the room
Mark M.
if it were something that "just worked", that'd be one thing
Andrei
ok.
Luca
hi all
Mark M.
but, as I mentioned, it sucks, and so not maintaining it will only make it suck worse over time
hello, Luca!
Luca: it's your turn -- do you have a question?
Andrei
Hi Luca
Luca
yes
i'm using some custom views and to avoid too many allocations i'm caching objects like rect and paint in static variables, obviously only those that i know don't change when using the same view multiple times, is it a good practice?
Mark M.
"i'm caching objects like rect and paint in static variables" -- yuck!
caching them as data members may be OK, done carefully
caching them as statics seems like overkill and risky
10:10 AM
Andrei
My turn?
Mark M.
Luca: I'll swing back to you in a bit to follow up
Andrei: go ahead
Andrei
Given the same context as before: initially I was also forcing an "artificial click" on an item from the first fragment's list via some code placed in "onLoadFinished()", in order to populate the details fragment. Now after adding the 3rd fragment to add items to the list in the 1st fragment, my program crashes when getting back from the 3rd fragment to the first two fragments. Namely, "getlistview()" which I used in "onLoadFinished()" crashes with the message "java.lang.IllegalStateException Content view not yet created". How do I force a selection without getting into this trouble?
Mark M.
setSelection() isn't working for you?
though, reading the JavaDocs, that might not work in touch mode...
is your ListView single-choice mode?
Andrei
I think it didn't work, if I recall correctly
yes
Mark M.
then it'd be setItemChecked()
which should toggle your activated state, assuming that you are using one
Andrei
ok, I'll try that
When people had the same error it seemed that the loader got activated before the view was re-created
or something like that
10:15 AM
Mark M.
Luca: do you have another question, or a follow-up from the first one?
Andrei
(but not with your loader)
Mark M.
Luca: if you do come up with another question, say so, and I'll route back to you
Andrei: if you have more, go ahead
Andrei
One more from me: I notice that when I come back from the 3rd fragment, my 1st fragment doesn't go through "onCreateView()", though the Fragments documentation suggests it should: http://developer.android.com/images/fragment_li... . Is this normal?
Mark M.
your first fragment would not have gone through onPause()/onStop()/onDestroyView() just by being pushed onto the back stack
hence, there would be no onCreateView() when coming back after popBackStack()
your view is already created
Andrei
But it goes through the others after onCreateView(), when returning from the 3rd fragment
Mark M.
what are "the others"?
Andrei
I did not check onPause and the following, but I checked everything from onCreateView() on
i.e. onActivityCreated(), onStart() and onResume()
10:20 AM
Mark M.
:: shrug :: I don't know what to tell you, sorry
Luca
i haven't other questions, i will avoid to use static rect/paint in views maybe it was an overoptimization/overkill furthermore views are already cached by adapters, i'm trying to allocate fewer objects possible to reduce the intervention of the garbage collector because i'm afraid of it.. "GC stops the world"
Andrei
it goes through all these but not through onCreateView() so I was wondering why, but it's not an essential question anyway
coming back to your answer to my first question, you suggested to make the loaders available globally to all fragments. This means I should use some static variables to hold them?
Mark M.
Luca: GC doesn't usually "stop the world" on Android 3.0+, though it can consume CPU cycles
Andrei: no, have the Activity hold it, and the fragments can talk to the activity
assuming the 3rd fragment was the one doing the insert(), that's all the broader access you'd need
Andrei
indeed
they all belong to the same activity
that was all from me
10:25 AM
Andrei
thanks for your time and advices!
Mark M.
you are very welcome
actually, could one or both of you do me a quick small favor, and try visiting https://stackoverflow.com in a browser?
I'm seeing an untrusted certificate error, and I'm trying to determine if that's just my environment
Andrei
I get a "This is probably not the site that you are looking for!"
SSL Error, indeed
Mark M.
they're probably doing work related to the "heartbleed" OpenSSL bug
Luca
i get the error too
Mark M.
thanks!
10:35 AM
Andrei
has left the room
11:00 AM
Mark M.
that's a wrap for today's chat
the next one is Monday at 4pm US Eastern Daylight Time
the chat transcript will be posted shortly to http://commonsware.com/office-hours/
have a pleasant day!
Luca
has left the room
Mark M.
turned off guest access

Yesterday, April 7

 

Office Hours

People in this transcript

  • Andrei
  • Luca
  • Mark Murphy