Office Hours — Today, December 11

Wednesday, December 5

Mark M.
has entered the room
Mark M.
turned on guest access
Dec 11
4:00 PM
Carlos V.
has entered the room
Mark M.
howdy, Carlos!
how can I help you today?
Carlos V.
Hi Mark!
I have an issue implementing ActionBar Items between fragments that share an activity (tablet configuration). Let me paste my full problem description.
I have an app with 3 Activities and 3 fragments for phone configurations and 2 activities and 3 fragments for tablet configurations. In the phone configuration, the first fragment (and parent activity) inflate and handle a list view and the other 2 activities/fragments are used when editing an item (i..e onListItemClick is called) or when a new item needs to be added to ListView (i..e user pressed "new item" ActionBar item). In the tablet configuration, the MainActivity loads the "ListView fragment" in the left-hand pane and when an item is clicked it loads a "details fragment" in the right-pane. When a new item is to be added a new activity/fragment is called just like in the phone configuration.
Mark M.
OK
Carlos V.
In the phone configuration everything works fine since each fragment is setup to to inflate its corresponding ActionBar menu through setHasOptionsMenu(true) and onCreateOptionsMenu(). However, in the tablet configuration, when a user clicks on an item in the ListView, the action bar contains the AB items for both the original "details fragment" (listview) as well as the AB items from the "details fragment". Since both the ListView fragment and the details fragment share the same action bar, what is the proper way to remove unneeded AB items?
View paste
Expectation:

What I expect to happen in the app is that when an item is clicked only the AB items related to the details fragment are shown and when the user navigates out of the detailview (i..e user press back buton or done/cancel/delete AB button) the ActionBar gets updated to show the original items created by the ListView fragmnet.
Mark M.
"Since both the ListView fragment and the details fragment share the same action bar, what is the proper way to remove unneeded AB items?" -- the idea is that the ListView's action bar items should still be relevant
when the user presses the BACK button, they should exit the activity entirely
4:05 PM
Mark M.
why do you think that actions related to the list are invalid while the list is still showing, just because the details are also showing?
Carlos V.
Fire drill at work. give me a sec.
Gabriele
has entered the room
Mark M.
howdy, Gabriele!
Carlos: chime in when the fire drill is over and you are back
Gabriele
hello :)
Mark M.
in the meantime... Gabriele: do you have a question?
Gabriele
I'm populating a MatrixCursor inside an asynctask (because I'm parsing the returned webresponse), anyway now I want to pass the returned MatrixCursor to my SearchProvider (ContentProvider extension), is this a bad thing? How should I do?
I've tried returning it to the mainactivity, but it seems "empty" (no rows)
Peri H.
has entered the room
Peri H.
Hi Mark,
Mark M.
"How should I do?" -- I have no idea
Peri H.
New quetions - are you available?
Mark M.
Peri: I will be with you shortly
Gabriele
I means, is a bad idea returning a MatrixCursor?
mean*
Mark M.
Gabriele: I have not implemented search suggestions except via the basic SearchRecentSuggestionsProvider, which does not involve a Cursor
4:10 PM
Mark M.
what is your SearchProvider?
Gabriele
it's really simple, I have only one method public Cursor query
which should return my matrixcursor
but I've created this matrixcursor inside an asynctask elsewhere
Mark M.
I have never used a MatrixCursor with a ContentProvider
I would expect it to work as a return value
but, again, I have not tried it
Gabriele
ok, thank you
Mark M.
put breakpoints in query() and confirm that the value you are returning is not empty
Peri: your turn for a question!
Peri H.
ok, thanks.
I'm have an activity returning a result and am debugging why mMap (in the intent) is coming back null.
I wonder if you have any suggestions on tracking this down.
Mark M.
I do not know what mMap is
Peri H.
In the child activity, I have a breakpoint on "finish". At that point, I can see intent, the map, and the map contents.
Mark M.
what is "the map"? what is "the map contents"?
Peri H.
Then, at another breakpoint in the parent app, at onActivityResult, I look at the "data" param. mMap is null.
Mark M.
I do not know what mMap is
4:15 PM
Mark M.
I cannot help you if you cannot explain what mMap, "the map", and "the map contents" are with respect to this Intent
Peri H.
Ok. In the intent, there's mExtras. In the latter there's mMap. mMap is a hash of the various extras.
Mark M.
are you referring to the source code for Intent itself?
if so, I cannot help you with modifications to the Android framework
Peri H.
I'm looking at the variables in the debugger - so, not quite the source code.
I'm not modifying the framework. Just trying to use Intents to pass data back to the parent activity.
Mark M.
that's nice and all, but I use Intent via the public methods in the Android SDK
I do not know anything much about the internal implementation of Intetn
Peri H.
Yes, I am too.
Mark M.
er, Intetn
er, Intent
(I'll get that typed correctly eventually)
but how am I supposed to tell you why "mMap" is null, when I did not write the Intent class?
Carlos V.
Mark I'm back. So is there at least a way to re-order the AB items?
Mark M.
you do not access "mMap" directly
(Carlos: I will be back with you shortly)
Peri: what, in terms of your *code* (not your *debugger*), is going wrong?
Peri H.
Well, I was hoping that you might understand the nuance on what happens to intents when returning them to the parent via onActivityResult. In otherwords, where did my extras go?
As I just said - it's losing the extras.
4:20 PM
Mark M.
are both activities in your app and in the same process?
Peri H.
Yes
Mark M.
have you checked to see if it is the same Intent object in both places?
Mark H.
has entered the room
Peri H.
No. How do I do that?
Mark M.
actually, never mind that -- I'm not sure that they will be the same anyway
(Mark: I will be with you in a few minutes)
Peri: I haven't returned data myself via extras from startActivityForResult()
try tucking some distinctive Uri into the Intent you are returning
then see if the Uri gets to the original activity
if that too winds up null, then perhaps there is something wrong with the timing of setResult()
setResult() is a bit picky -- you have to call it before onPause(), for example
if the Uri makes it there, but the extras do not... that's quite the puzzler
Peri H.
Ok, that's a good idea. Well, I was hoping you might have an answer up your sleeve :) Let me get back to you if there's still time and let you know about the uri experiment.
Mark M.
AFAIK, you should be able to return extras, but I haven't done so myself, and I've never researched the point
OK
Carlos: you can have the fragments call invalidateOptionsMenu(), IIRC, which should trigger a rebuild of the action bar
but the general idea is that the action items for a fragment should be relevant so long as the fragment is on the screen
Carlos V.
Should I call invalidateOptionsMenu during the onCreate of the Details fragment?
Mark M.
I get the feeling that you are trying to use the detail fragment almost like a modal dialog, which isn't the idea
with respect to the timing of invalidateOptionsMenu(), I have no idea
Carlos V.
Let me explain.
4:25 PM
Carlos V.
The app is a task app. right-pane has list of tasks and ActionBar contains refresh AB item and "new task" item
Mark M.
right pane has the list?
usually the list is on the left
Carlos V.
when a user presses "new task" it adds items for done/delete/cancel "task edit"
Mark M.
what's on the left, if not the list?
Carlos V.
right pane shows selected task
yes list on left selected task on right pane
Mark M.
OK
Carlos V.
Maybe is implementation issue
What is the suggested way to deal with AB items on right pane
Mark M.
simply have them
Carlos V.
can I at least sort list AB items to be listed first and then AB items from right pane?
right now they are in random order
Mark M.
in theory, you could use orderInCategory for that in the menu XML, but I haven't tried it
Carlos V.
will invalidateOptionsMenu() fix sorting issue
?
Mark M.
probably not
Carlos V.
What is the recommended pattern for this case?
Mark M.
don't change the action bar when the user presses "new task", unless you are replacing the right-hand fragment
Carlos V.
I think at least it would make sense to have them in order of appearance. Meaning, listview items first followed by details fragment items
Mark M.
that is perfectly reasonable
Carlos V.
so should I use "Action Mode" instead?
Mark M.
and, I thought that was how it worked
I can't answer that, as I do not understand sufficiently your UI
Carlos V.
No, currently when the detail fragment is created the action bar is alternating order between items from both fragments
Mark M.
again, try orderInCategory in your menu XML
4:30 PM
Mark M.
let me take questions from the others, and I'll be back with you in a bit
Mark: do you have a question?
Carlos V.
I guess I got confused as to the proper pattern for the tablet configuration. For phones it is working fine.
I'll come back for next office hours. Thanks for feedback
Mark H.
Yes, 1st let me apologize for tweeting to you outside of Office Hours in a moment of coding frustration
Mark M.
it's more that I have difficulty providing support in 140 character chunks
especially when I don't understand the question :-)
so, go ahead
Mark H.
I'm trying to write what I though would be a simple app to over-ride the double-tap to zoom function and actually send a mouse double-click, but I can't seem to figure out any way to actually send a double-click
Mark M.
first, IIRC, we are talking about WebView?
Mark H.
I've taken the WebView and I have javascript working, but it won't pass the double-tap through
Mark M.
what is "it"?
Mark H.
Lol..Webview.
Mark M.
where and how are you intercepting the double-tap? JavaScript? Java? other?
4:35 PM
Mark H.
I've written the intercept in Java which works fine, but I can't figure out what action to do after the intercept.
Mark M.
well, if you know the JavaScript code to execute that triggers some DOM double-click event, in theory you can use loadUrl("javascript:...") to execute it (where ... is the code in question)
but I am not a low-level JavaScript guy, so I haven't the foggiest notion what the right events are, let alone whether you can raise them from JavaScript
I'll be a bit surprised if you can do it successfully from Java directly
only because I would think WebView would interpret them as just another double-tap, giving you an infinite loop
let me field questions from the others, and I'll be back with you in a bit
Gabriele: do you have another question?
Carlos V.
has left the room
Mark M.
Peri: do you have another question?
4:40 PM
Mark M.
Mark: do you have another question?
Mark M.
has entered the room
Mark M.
testing...
Mark M.
OK, well, if anyone has any further questions, just ask!
Mark M.
has left the room
Peri H.
I do have another question, but I'll save that since I'm saturated with this intent problem.
Mark M.
OK
Peri H.
I tested putting the uri in the intent. That's gone, too. When I "call" the child activity from another parent, it returns properly. I don't know if it makes sense to involve you with this any further unless you have any clues as to why I'm losing the intent.
4:45 PM
Peri H.
I will add one more consideration. I have three activities in play here. A start B which starts C which starts another copy of B. B returns to C. It's there that the intent is getting lost.
Mark M.
oh, yeah, that may not work well
startActivityForResult() really isn't designed for something like this
it's more for simple pickers and the like
Peri H.
Really? What other way is there to start activities then?
Mark M.
startActivity()
Peri H.
Yes, but with results?
Mark M.
startActivityForResult() is not designed to trigger anything beyond a *single* activity
which returns the result
B should not start C, let alone C starting another B
anything beyond A starting B, and B sending a result back, is beyond what startActivityForResult() was written for
Peri H.
Ok, but it is only starting one at a time. Can't an activity exist multiple times on the activity stack? Maybe that'ts the problem.
Mark M.
"Can't an activity exist multiple times on the activity stack?" -- by default, yes
though you can change that via android:launchMode or flags on the Intent to force reuse of existing activities
Peri H.
How do you come to the conclusion that there can be only one level of startActivityWithResult? I'm sure there are plenty of google apps which go more than one level. For example: calendar app -> edit event -> date picker.
Mark M.
"How do you come to the conclusion that there can be only one level of startActivityWithResult?" -- by nearly five years of providing developer support for Android
Peri H.
(by the way, if my tone comes across angry, forgive me. I'm totally not)
4:50 PM
Mark M.
calendar app would not use startActivityForResult() for "edit event"
and "date picker" is a dialog, usually
Mark H.
has left the room
Mark M.
you are not the first person to get tripped up with nested or complex startActivityForResult() chains
I forget whether there has been official Googly guidance on the matter
Andrew G.
has entered the room
Mark M.
howdy, Andrew!
Peri H.
Hmm. Well what do you suggest I do? I'll simplify my actual failure case. I have a case where the user needs to start an editing session. That is done by a child activity. In that activity, there's some other editing that needs to be done. So I start a nested activity.
Andrew G.
hello!
Mark M.
Peri: why are you using startActivityForResult() for an "editing session"?
Andrew: do you have a question?
Andrew G.
I do but I'm afraid it's rather general
Mark M.
Andrew: go ahead, and I'll see what I can do
Peri H.
I need results to update some database updates in the parent activity. I might be able to move the updates to the child, but that's tricky.
Mark M.
Peri: you most certainly should be moving the updates to the child
Peri: activities are not function calls
Andrew G.
I'm looking into finding the best way to display an array of Bitmaps in a Gallery type view. I have the requirement that I cannot store them on disk and I do not want to call an external gallery intent
I was looking at the ViewPager
I wonder if there arent any reasonable libraries for me to use to do such a thing
Mark H.
has entered the room
Mark M.
by "Gallery type view", do you mean the Gallery widget, or the Gallery app?
Andrew G.
I want to support zoom/pan/swipe
app, sorry
Peri H.
If I do that, then I need to reopen the datatbase in the child. I was trying to avoid that.
Mark H.
Sorry Mark. My Mac crashed...
Mark M.
Peri: you should either have a singleton SQLiteOpenHelper or a ContentProvider
Mark: ah, OK -- welcome back!
Mark: since we're short on time, I'm trying to multiplex, so feel free to ask a question
Peri H.
By singleton, do you mean something that is sharable among activities?
4:55 PM
Mark M.
Andrew: well, Gallery is probably a mix of ViewPager and GridView
Andrew: you can look at the implementation of it for ideas
Peri: I mean singleton, as in a Java singleton
Peri: which is shareable among activities, threads, etc.
Andrew G.
I realize we are at the end of your time here. For future reference do you consider this a forum for discussion or simply a way, as you said, to multiplex your advice to all?
Mark M.
Andrew: this is for Q&A -- I try to handle one person at a time, until we get to crunch time :-)
Andrew G.
For instance, do you frown upon helping each other during these chats? Should we defer to you exclusively?
Mark H.
great, the long and short of my question is if you know of a way to SEND a mouse click from Java? I can't find anything.
Mark M.
Andrew: you are welcome to chime in on others' questions, though that's not the typical flow
Mark: not sure if you got any of my original replies
Mark: if you know how to send the right DOM events from JavaScript, use loadUrl("javascript:...") to send them
Peri H.
I see. I've never used singletons in Java, but it would work. However, I don't have time to impelement that for this version. I hope I can find another workaround for now. Thanks so much.
Mark M.
Mark: but I don't know what the right DOM events are, as I'm not a low-level JavaScript/DOM kind of guy
Peri: OK
Mark H.
Ok, I've not done Javascript, but I'll check that out.
Mark M.
Andrew: for a sense of the flow of these things, you can check out the archives: http://commonsware.com/office-hours/
Andrew: usually, they aren't as crowded :-)
Mark: I haven't the foggiest notion how to issue mouse events to yourself from Java, as there is no obvious KeyEvent associated with mouse button clicks
5:00 PM
Andrew G.
OK. As for my question I see you cover the ViewPager in the book. I will take a look at that and some other resources and perhaps you'll see me back here Thursday
Mark H.
I don't know if it helps, but here is the Javascript:
View paste
 <tr onclick="selectRow(event);" ondblclick="openPairingDetails(8223426);" id="r_0">
                    <td style="text-align:center;" class="unSelectedCell selectable numCodeCol" id="tsn_8223426">BAF2</td>
                    <td style="text-align:center;" class="unSelectedCell selectable dateCol">12/13/2012</td>
                  </tr>
Mark M.
Mark: you could try creating a non-WebView activity, log the onKeyDown()/onKeyUp() stuff, see what mouse events result as (if anything), then try to replicate it
Andrew: sounds like a plan
Mark: yeah, that means nothing to me in isolation
and that's a wrap for today's chat
there's an extra chat tomorrow, to make up for one I needed to cancel from last week due to technical difficulties
(referred to by some as a hotel with singularly craptastic Internet)
Mark H.
HAHA, thanks Mark
Mark M.
so, next chat is tomorrow, 7:30pm Eastern
have a pleasant day, all!
Andrew G.
has left the room
Gabriele
has left the room
Peri H.
has left the room
Mark H.
has left the room
Mark M.
turned off guest access

Wednesday, December 5

 

Office Hours

People in this transcript

  • Andrew Gibel
  • Carlos Vega
  • Gabriele
  • Mark Hochstein
  • Mark Murphy
  • Mark Murphy #2
  • Peri Hartman