Feb 19 | 9:55 AM |
Mark M. | has entered the room |
Mark M. | turned on guest access |
Feb 19 | 10:30 AM |
Oliver | has entered the room |
Mark M. |
howdy, Oliver!
|
Mark M. |
how can I help you today?
|
Feb 19 | 10:35 AM |
Oliver |
Hi - sorry I am a bit late...I owed you $$$ ;)
|
Oliver |
right...couple of questions
|
Mark M. |
you are welcome to join whenever you want within the hour
|
Mark M. |
and thanks for renewing! :-)
|
Oliver |
boring question first
|
Oliver |
I am using nested fragments
|
Oliver |
special map fragment
|
Oliver |
and I need to configure that fragment a little
|
Oliver |
either to monitor the current GPS position
|
Oliver |
_OR_ just to show data (several tracks)
|
Oliver |
I have working code...so just a thumbs up would be great
|
Oliver |
I was originally sending arguments
|
Oliver |
partly because I am using a tabs adapter (just using a ViewPager) and args are easy to send with that
|
Oliver |
something like:
mTabsAdapter.addTab(mTabHost.newTabSpec("map").setIndicator(res.getString(R.string.map)),
MapFragment.class, args);
|
Oliver |
now...the problem with that...I found was that in other cases I Load the data
|
Oliver |
and swapping the fragment requires commitAllowingStateLoss()
|
Oliver |
so what I ended up doing was two code paths
|
Oliver |
(In the MapFragment)
|
Oliver |
View paste
|
Feb 19 | 10:40 AM |
Oliver |
and onActivityCreated(...)
|
Oliver |
View paste
|
Oliver |
that means I use the first block with loaders (by keeping a reference to the MapFragment in the parent)
|
Oliver |
and the second block I use with TabAdapters and the like
|
Oliver |
sorry
|
Oliver |
does that make sense?
|
Mark M. |
um, not especially, to be honest
|
Mark M. |
this is kinda complicated for a chat
|
Mark M. |
what are your specific concerns with your implementation?
|
Oliver |
that I am communicating the setup via two means
|
Oliver |
a) arguments
|
Oliver |
b) fragment methods
|
Mark M. |
the problem with "fragment methods" is that there is no automatic onSaveInstanceState() support, as there is with arguments
|
Mark M. |
so long as you are handling configuration changes properly for the data supplied by "fragment methods", that's OK
|
Mark M. |
the beauty of the arguments Bundle is that it is saved for you without further work
|
Oliver |
umm...I haven't
|
Mark M. |
sounds like another item for your to-do list... :-)
|
Oliver |
but the problem with loading (in my case) sessions
with a loader is sending them to the Fragment as an argument - I have
to do a transactions...and that requires a commit with state
loss...which I am not too happy about - because I am not too sure on the
consequences (great book topic ;)
|
Feb 19 | 10:45 AM |
Oliver |
(sorry typos)
|
Mark M. |
I have yet to run into a valid use case for commitAllowingStateLoss()
|
Mark M. |
there may be one
|
Mark M. |
but I usually find that it is a (sometimes flawed) workaround to some other problem
|
Mark M. |
Loaders also should be configuration-change-aware, though
|
Mark M. |
but I am not sure why you think that "transactions" (fragment? database? other?) require "commit with state loss"
|
Oliver |
so the book topic - Load the tracks and then pass them to the MapFragment using arguments
|
Oliver |
View paste
(7 more lines)
|
Mark M. |
other than the commitAllowingStateLoss() call, nothing leaps out at me as being necessarily a problem with what you have there
|
Oliver |
I have seen some folk use handlers but my _feeling_ is that does not address the problem
|
Oliver |
and you are with me that I cannot use commit()
|
Oliver |
?
|
Oliver |
IllegalStateException etc.
|
Feb 19 | 10:50 AM |
Mark M. |
again, I find that such an exception indicates some other problem
|
Feb 19 | 10:50 AM |
Mark M. |
but without a stack trace and details, I cannot help much with that problem
|
Oliver |
well it is because you cannot do fragment transactions within a loader call
|
Mark M. |
that seems awfully specific
|
Oliver | |
Mark M. |
oh, I know what that method JavaDocs says
|
Mark M. |
again, usually I find that you can solve the underlying problem in some other way
|
Oliver |
ok
|
Oliver |
I think we can leave it there - I will deal with restoring the fragment
|
Mark M. |
if you can create a sample project that
demonstrates your claim about "cannot do fragment transactions within a
loader call", I'll be happy to look at it
|
Oliver |
sure...I can easily do that
|
Oliver |
So the next question..I might have to catch you on Thursday
|
Oliver | |
Mark M. |
send the sample to mmurphy@commonsware.com and reference this chat, so I know the context
|
Oliver |
I am not sure if setIntent works as I expected with a singleTop flag
|
Mark M. |
I avoid setIntent() too
|
Mark M. |
I have not run into a situation where it was needed
|
Oliver |
search activity
|
Mark M. |
just hold onto the Intent somewhere else (e.g., data member, parameter to methods)
|
Mark M. |
again, hold onto the Intent somewhere else
|
Mark M. |
the issue is your reliance on getIntent() as being the "one-stop shopping" way to get the launching Intent
|
Feb 19 | 10:55 AM |
Mark M. |
check some other spot first (for what you got in onNewIntent()), and if that's null, fall back to getIntent()
|
Mark M. |
this avoids setIntent() and any oddities that it may have
|
Mark M. |
(and I get the sense that setIntent() is odd, given some questions that have come up over the years)
|
Oliver |
I am with you...it is not normally a problem...only if the activity is killed off
|
Oliver |
this case comes up from search
|
Oliver |
search (query comes in from intent)
|
Mark M. |
"killed off"?
|
Oliver |
new query comes in...you can see the new search
results...you click on a search result...and lots more...then navigate
back....and for end up going to the search results from the first query
|
Oliver |
running out of time...maybe best if I e-mail you...I can put it out on SO _but_ I think it is a bug
|
Mark M. |
it's entirely possible that it's a bug, but, again, I don't use setIntent()
|
Oliver |
ha! the documentation says use it with onNewIntent ;)
|
Mark M. |
it may be worth asking on SO, in case somebody else has a solution
|
Oliver |
awesome...I'll put those samples up and catch you on Thursday...cheers for you help.
|
Oliver |
*your
|
Mark M. |
OK
|
Mark M. |
note that Thursday's chat is at 4pm Eastern
|
Feb 19 | 11:00 AM |
Oliver |
ok...will do...I had a funny feeling it is 21:00 UK...but I'll check...all the best
|
Mark M. |
that sounds about right
|
Mark M. |
the transcript of today's chat will be posted to http://commonsware.com/office-hours/ shortly
|
Mark M. |
have a pleasant day!
|
Oliver | has left the room |
Mark M. | turned off guest access |