Office Hours — Today, July 16

Thursday, July 11

Jul 16
3:50 PM
Mark M.
has entered the room
Mark M.
turned on guest access
4:00 PM
EGHDK
has entered the room
Mark M.
hello, EGHDK
how can I help you today?
EGHDK
View paste
Hey Mark. I've been having a really tough time with recording video, and also getting images from gallery. I have taking a picture working fine.
I'm going to pastebin my sample app activity code for just Video and Gallery, I was wondering if you could see if there is anything wrong with it.
Mark M.
well, you aren't doing anything with the results
what specifically does "a really tough time" mean?
EGHDK
If you could just look at the intents first I guess. Because I keep getting a null response from these two intents. I realize my onActivityResult is omitted for now. Just wanted to get a quick diagnosis with the intents.
Mark M.
what do you mean by "a null response"?
EGHDK
Okay, I guess I will post my onActivityResult. Give me one second.
4:05 PM
Mark M.
that's a mighty long second :-)
4:10 PM
EGHDK
That's what I'm sayin... I'm trying to pull out my other code so it's clear. But I'm also testing it really quickly to make sure it's not magically working.
Mark M.
could you perhaps just explain, in words, what you mean by "a null response"?
I'm not asking to see your onActivityResult() implementation
EGHDK
Okay so I basically do this with the video Result
View paste
mVideoUri = intent.getData();

if (mVideoUri == null) {
//Toast "It's null!"
return;

}
4:15 PM
EGHDK
I always get the Toast to show. So `intent.getData()` get's returned as null...
4:15 PM
Mark M.
and you are checking that resultCode is ACTIVITY_OK first?
EGHDK
Yep
Mark M.
then your particular test device's video recording app does not appear to be following the ACTION_VIDEO_CAPTURE contract
you might try switching to passing in a location via EXTRA_OUTPUT and see if that helps
EGHDK
BUT, my biggest issue is that Google has a sample app for getting this, but yet it doesn't work on my phone either. It returns null.
I have stock android running on my gnex, and the stock camera app is running.
"you might try switching to passing in a location via EXTRA_OUTPUT and see if that helps" can you explain. I'm not sure what that means.
Mark M.
"The caller may pass in an extra EXTRA_OUTPUT to control where the video is written. If EXTRA_OUTPUT is not present the video will be written to the standard location for videos, and the Uri of that location will be returned in the data field of the Uri."
you are relying on the behavior in the second quoted sentence
I'm suggesting that you try the first quoted sentence and see if that proves more reliable
in general, though, any time you are asking a third-party app to do something, the app may not completely comply
I would expect Google's own camera app to behave properly
EGHDK
Yeah... I thought it was my code that was broken...
Mark M.
but, Google can have bugs just as much as anyone else
not in any obvious fashion
4:20 PM
EGHDK
And then I looked in your book and I was like what!? Theres no guide to taking video?
Hahaha
Mark M.
actually, you'll get some of that in the next update
however, my focus is more on taking photos and video yourself
versus relying on potentially-shaky third-party apps
EGHDK
But I guess this output thing will be a good start. It's just weird because getting data from camera intent works fine.
Mark M.
taking the videos yourself has its own set of challenges, though
EGHDK
"focus on taking photos and video yourself" YES PLEASE
Can't wait for that update. Version 5.0 you think?
Mark M.
yes, presently scheduled for release on Monday
in terms of the images, that too looks OK, though I have never tried ACTION_PICK on that particular CONTENT_URI before
you could go with ACTION_GET_CONTENT and image/* for a MIME type as an alternative
4:25 PM
EGHDK
Where are you reading that?
Mark M.
where am I reading what?
EGHDK
ACTION_GET_CONTENT
Mark M.
EGHDK
Okay cool. I'll look into that too. This is getting interesting. I thought this would have been a bit simpler.
Mark M.
if it were simpler, you wouldn't need to subscribe to balding guys' books, now, would you? :-)
EGHDK
Hey, baldy knows what he's talking about.
Hahah. You've got a lot of experience with this. And with that comes wisdom.
It's more like a 40 dollar book of wisdom.
Mark M.
bad news, though
EGHDK
What?
Mark M.
the price went up to $45 back in January
EGHDK
Eh. $45 dollar book of wisdom. I wish other books I bought came with updates...
Went into the store the other day, and saw a few android dev books. Picked em up. Most were priced at like 50-60 bucks. No way.
4:30 PM
EGHDK
Oh! Quick question. Is there any place you know of that will print this pdf for me? I could sure use it in print. I've looked online but no one really prints in the thousands of pages. lol
Mark M.
I would assume FedEx Office, Staples, etc. would do it, via their online print ordering stuff
the size of the PDF file might be more of an issue than the page count
and then you'd need a bunch of three-ring binders or something
I make the PDF specifically be printable (particularly double-sided), but that's usually impractical at the level of the entire book
individual chapters are more realistic
EGHDK
Yep. Alright so my next problem is with gallery.
Here is my onResult
So my gallery shows up, and I get my Android folder to choose from (Camera, Screenshots, GroupMe)
4:35 PM
EGHDK
If I choose a screenshot or a groupme picture, I get a Toast "1" and a toast "2".
If I choose a picture from my camera folder, the screen goes black for like 10 seconds, and doesn't toast anything.
Can't figure that out.
Mark M.
once again, the problem would appear to be with the camera app, not your code
EGHDK
It's coming from the stock gallery app
Mark M.
what do you intend to do with the image once you get it?
4:40 PM
EGHDK
View paste
There has to be some way to fix it though. Here is a pastebin of my folders and results. Maybe you'll see something similar between them all. 
http://pastebin.com/F1KjcGp8
I intend to display a little icon of it, and possibly join it with another image.
Mark M.
again, the problem isn't with your code
EGHDK
But I can't do anything If I can't get half of the images in my gallery.
You think it's a memory problem?
Mark M.
and that's a problem with the gallery app
wait
do you actually get a chance to choose the image in the gallery app?
EGHDK
Yeah
Mark M.
hmmmm...
EGHDK
It only hangs when I choose the specific image in the folder I specified.
Mark M.
I would recommend switching to LogCat (via Log.d() and such) rather than toasts, so you are sure that you do not miss anything
the memory issue would only come up if you actually tried loading the image, which would imply that you got past your "1" toast
EGHDK
And it hangs right when I touch the image. So it's the gallery app that's actually "hanging"
4:45 PM
Mark M.
and if that's the case, the problem is in the gallery app
EGHDK
Okay, I'll accept it. lol Thanks.
Mark M.
there's nothing you can really do that should screw up another app in this fashion
but, again, try using LogCat instead of toasts
EGHDK
Yep.
Mark M.
or use breakpoints
it may be that you actually *are* getting control back, but things are visually stuck
it is well within reason that you will encounter memory issues with your current implementation, though
EGHDK
How would I check that?
Mark M.
if you get a log message for "1", then you got to that line
or, if you hit a breakpoint where you are presently toasting "1", you got to that line
EGHDK
True. Okay I will try that.
Okay, two more questions!
One is a sample app that I made that I don't get how it's working.
Mark M.
because you're really really good
:-)
EGHDK
Okay so I have a very simple app. Two activities. MainActivity has one button, and SecondActivity has an textView.
When I click the button I go to the secondActivity.
4:50 PM
EGHDK
When I'm in the second activity and press the home button, my overriden onStop method get's called.
My onStop method set's the text of the textView
When I get back to my app, from recent apps, I see the text has been changed.
Why is that?
Mark M.
because you changed the text
and onStop() is called when the activity is no longer visible
EGHDK
So Sorry onstop() I set a String variable to a value.
On resume I setText to the variable.
I didn't know variables stay alive when you leave an activity?
Mark M.
data members of an object live as long as the object dos
er, does
your activity was not destroyed
it was just moved to the background
and your process was not terminated between the time you pressed HOME and the time you went back to the activity
hence, the data member is still there
EGHDK
Okay, so I reload the application on my phone.
SO everything is gone.
Now, I press the button on mainActivity
but then I press the back button
onStop() get's called.
And I'm back at the MainActivity.
I press the button again. I don't see my textView set.
Mark M.
correct
EGHDK
That's because I created a totally new "SecondActivity" correct?
Mark M.
correct
EGHDK
So on the Intent, I tried doing setFlags
FLAG_ACTIVITY_REOERDER_TO_FRONT
4:55 PM
EGHDK
Reading the documentation, I should get the result I want. (textView is set to variable)
Mark M.
on *what* Intent?
EGHDK
On the intent created by the button press on the MainActivity
Basically, once I start my secondActivity, i want to keep back going to it.
Mark M.
then you have to do something to change the BACK button behavior
EGHDK
REORDER_TO_FRONT should have done the trick... no?
Mark M.
no
why would it?
BACK destroys the activity
period
end of story, by default
EGHDK
Really?
Wait wait wait.
Why didn't I know this.
Oh man.
So back calls finish?
Mark M.
effectively, yes
EGHDK
"effetively"?
effectively*
Mark M.
well, there are a few more steps between pressing BACK and finish() being called
EGHDK
Where would I go to see what the back button actually does?
Mark M.
and I'm not 100% certain if finish() is literally called, or something else is called that does the same thing
hang on
5:00 PM
Mark M.
the primary entry point into your app for BACK presses is onBackPressed()
(there should also be some calls to onKeyEvent() and such, and I'm not sure of the precise timing of those)
EGHDK
Okay. Sweet. Alright, so finish() destroys an activity, and back buttons destorys the activity. But back does not necessarily call finish.
Mark M.
the default implementation of onBackPressed() will call finish() if there are no outstanding FragmentTransactions on the back stack
EGHDK
onBackPressed can't be used on fragments right
Mark M.
no, but a fragment created via a FragmentTransaction, where the transaction has addToBackStack() called on it, will be reversed on a BACK press
and that's pretty much a wrap for today's chat
next one is Thursday at 10am
EGHDK
Alrighty O.
Mark M.
the transcript of this one will show up at http://commonsware.com/office-hours/ shortly
EGHDK
Cool. Learned a lot. Thanks Mark. I have one more question that I'll hold out till Thursday.
Mark M.
have a pleasant day!
EGHDK
You too.
EGHDK
has left the room
Mark M.
turned off guest access

Thursday, July 11

 

Office Hours

People in this transcript

  • EGHDK
  • Mark Murphy