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!
|
Mark M. |
how can I help you today?
|
Carlos V. |
Hi Mark!
|
Carlos V. |
I have an issue implementing ActionBar Items
between fragments that share an activity (tablet configuration). Let me
paste my full problem description.
|
Carlos V. |
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?
|
Carlos V. |
View paste
|
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
|
Mark M. |
when the user presses the BACK button, they should exit the activity entirely
|
Dec 11 | 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!
|
Mark M. |
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?
|
Gabriele |
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?
|
Gabriele |
mean*
|
Mark M. |
Gabriele: I have not implemented search
suggestions except via the basic SearchRecentSuggestionsProvider, which
does not involve a Cursor
|
Dec 11 | 4:10 PM |
Mark M. |
what is your SearchProvider?
|
Gabriele |
it's really simple, I have only one method public Cursor query
|
Gabriele |
which should return my matrixcursor
|
Gabriele |
but I've created this matrixcursor inside an asynctask elsewhere
|
Mark M. |
I have never used a MatrixCursor with a ContentProvider
|
Mark M. |
I would expect it to work as a return value
|
Mark M. |
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
|
Mark M. |
Peri: your turn for a question!
|
Peri H. |
ok, thanks.
|
Peri H. |
I'm have an activity returning a result and am debugging why mMap (in the intent) is coming back null.
|
Peri H. |
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
|
Dec 11 | 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?
|
Mark M. |
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.
|
Peri H. |
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
|
Mark M. |
I do not know anything much about the internal implementation of Intetn
|
Peri H. |
Yes, I am too.
|
Mark M. |
er, Intetn
|
Mark M. |
er, Intent
|
Mark M. |
(I'll get that typed correctly eventually)
|
Mark M. |
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
|
Mark M. |
(Carlos: I will be back with you shortly)
|
Mark M. |
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?
|
Peri H. |
As I just said - it's losing the extras.
|
Dec 11 | 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 M. |
(Mark: I will be with you in a few minutes)
|
Mark M. |
Peri: I haven't returned data myself via extras from startActivityForResult()
|
Mark M. |
try tucking some distinctive Uri into the Intent you are returning
|
Mark M. |
then see if the Uri gets to the original activity
|
Mark M. |
if that too winds up null, then perhaps there is something wrong with the timing of setResult()
|
Mark M. |
setResult() is a bit picky -- you have to call it before onPause(), for example
|
Mark M. |
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
|
Mark M. |
OK
|
Mark M. |
Carlos: you can have the fragments call invalidateOptionsMenu(), IIRC, which should trigger a rebuild of the action bar
|
Mark M. |
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
|
Mark M. |
with respect to the timing of invalidateOptionsMenu(), I have no idea
|
Carlos V. |
Let me explain.
|
Dec 11 | 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?
|
Mark M. |
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
|
Carlos V. |
yes list on left selected task on right pane
|
Mark M. |
OK
|
Carlos V. |
Maybe is implementation issue
|
Carlos V. |
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?
|
Carlos V. |
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
|
Carlos V. |
?
|
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
|
Mark M. |
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
|
Dec 11 | 4:30 PM |
Mark M. |
let me take questions from the others, and I'll be back with you in a bit
|
Mark M. |
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.
|
Carlos V. |
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
|
Mark M. |
especially when I don't understand the question :-)
|
Mark M. |
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?
|
Dec 11 | 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)
|
Mark M. |
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
|
Mark M. |
I'll be a bit surprised if you can do it successfully from Java directly
|
Mark M. |
only because I would think WebView would interpret them as just another double-tap, giving you an infinite loop
|
Mark M. |
let me field questions from the others, and I'll be back with you in a bit
|
Mark M. |
Gabriele: do you have another question?
|
Carlos V. | has left the room |
Mark M. |
Peri: do you have another question?
|
Dec 11 | 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.
|
Dec 11 | 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
|
Mark M. |
startActivityForResult() really isn't designed for something like this
|
Mark M. |
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
|
Mark M. |
which returns the result
|
Mark M. |
B should not start C, let alone C starting another B
|
Mark M. |
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
|
Mark M. |
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)
|
Dec 11 | 4:50 PM |
Mark M. |
calendar app would not use startActivityForResult() for "edit event"
|
Mark M. |
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
|
Mark M. |
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"?
|
Mark M. |
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
|
Mark M. |
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
|
Andrew G. |
I was looking at the ViewPager
|
Andrew G. |
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
|
Andrew G. |
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 M. |
Mark: ah, OK -- welcome back!
|
Mark M. |
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?
|
Dec 11 | 4:55 PM |
Mark M. |
Andrew: well, Gallery is probably a mix of ViewPager and GridView
|
Mark M. |
Andrew: you can look at the implementation of it for ideas
|
Mark M. |
Peri: I mean singleton, as in a Java singleton
|
Mark M. |
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 M. |
Mark: not sure if you got any of my original replies
|
Mark M. |
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
|
Mark M. |
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/
|
Mark M. |
Andrew: usually, they aren't as crowded :-)
|
Mark M. |
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
|
Dec 11 | 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:
|
Mark H. |
View paste
|
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
|
Mark M. |
Andrew: sounds like a plan
|
Mark M. |
Mark: yeah, that means nothing to me in isolation
|
Mark M. |
and that's a wrap for today's chat
|
Mark M. |
there's an extra chat tomorrow, to make up for one I needed to cancel from last week due to technical difficulties
|
Mark M. |
(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
|
Mark M. |
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 |