Mar 3 | 3:55 PM |
Mark M. | has entered the room |
Mark M. | turned on guest access |
Mar 3 | 4:00 PM |
tinoper | has entered the room |
Mark M. |
hello, tinoper
|
Mark M. |
how can I help you today?
|
tinoper |
hello Mark
|
tinoper |
Well,I'm stuck with ViewPager with different layouts
|
Mar 3 | 4:05 PM |
tinoper |
View paste
|
tinoper | |
tinoper |
could you tell me some advice
|
Mark M. |
"Demo startup but crash when I choose another tab"
|
Mark M. |
you need to use LogCat and examine the Java stack trace associated with your crash
|
Mark M. | |
tinoper |
I didn't but I'm lost
|
Mark M. |
well, until you use LogCat and examine the Java stack trace associated with your crash, there is nothing that anyone can really do to help you
|
Mark M. |
in my book, there is a "Debugging Your App" chapter that also helps you to navigate LogCat
|
tinoper |
ok,got it.Maybe we could have another aproach for this issue.
|
Mar 3 | 4:10 PM |
tinoper |
I'm implementing new toolbar,viewpager,swipe avoiding old tabs.
|
Mark M. |
"swipe avoiding old tabs"?
|
tinoper |
Indeed,it's working but I always have to use the same layout structure.
|
Mark M. |
you mean for the pages in the ViewPager?
|
tinoper |
exactly
|
Afzal N. | has entered the room |
tinoper | |
Mark M. |
(BTW, hello, Afzal -- I will be with you shortly!)
|
tinoper |
SlidingTabs indeed
|
Afzal N. |
Hey Mark, I don't really have many questions, just lurking here I guess
|
tinoper |
hi Afzal
|
Mark M. |
(Afzal: OK)
|
Afzal N. |
hi tinoper
|
Mark M. |
tinoper: well, you commented out the code in your `PagerAdapter` that used different layouts for different position values
|
Mar 3 | 4:15 PM |
tinoper |
Yes,I did it because it doesn't work
|
Mark M. |
and if that code is crashing, you need to examine LogCat to look at the Java stack trace associated with the crash
|
tinoper |
but if you tell me that is the right way
|
Mark M. |
personally, I use fragments for my pages
|
Mark M. |
and then my PagerAdapter would just create different fragments based on position
|
tinoper |
maybe do you recommend another way
|
Mark M. |
if you want to use views for your pages, then your code may work
|
tinoper |
I'm not sure about what to use.I just know that I would like to have tabs that shows different layout for each tab.
|
Mar 3 | 4:20 PM |
Mark M. |
again, the code that you have commented out is the basis for having a View-based PagerAdapter, with different layouts for different position values
|
Mark M. |
and if you are having problems with that code, you need to debug that coded
|
Mark M. |
er, debug that codde
|
tinoper |
Maybe ,as you said before, fragments and PagerAdapter are the answer
|
Mark M. |
er, debug that code
|
Mark M. |
(sheesh, I can't type today...)
|
tinoper |
ok,I'll do it.
|
tinoper |
:)
|
Mark M. |
your problem is that your ViewPager is hosted by a fragment
|
Mark M. |
which means to have fragments be pages inside of the ViewPager, you have to use nested fragments
|
Mark M. |
that is possible but... messy
|
Mark M. |
I cover it in my main ViewPager chapter in the book
|
Mark M. |
(Afzal: if you come up with a question, just let me know)
|
tinoper |
I would like to avoid messy stuff.Your recommendation are enough for me.This is a great add value to your book.
|
Mar 3 | 4:25 PM |
Afzal N. |
Sure. I've been developing for Android for quite a while (2-3 years) but I've never really gotten into the habit of writing tests. For a library which runs a service, how would you recommend testing it?
|
tinoper |
I'll try both things,debug my code and dig again ViewPager chapter.
|
Mark M. |
tinoper: OK
|
Afzal N. |
(I have done API testing professionally but not with Android)
|
Mark M. |
Afzal: what do you mean by "a library which runs a service"?
|
Afzal N. |
It's a library that executes a service, in this case, for motion recognition in the background
|
Mark M. |
do you mean a library that *implements* a service?
|
Mark M. |
or else, where is this service coming from?
|
Afzal N. |
More like there's a class in the library that calls startService on another class that extends a Service, both present in the library
|
Mark M. |
OK, so you have a library that implements a service, plus has a custom API for interacting with the service, right?
|
Afzal N. |
yup
|
Mark M. |
OK, now I'm with you
|
Mark M. |
personally, I'd tend to focus on testing the insides of the service itself
|
Mark M. |
though in your case, you may have other problems first
|
Mark M. |
by "motion recognition in the background", do you mean off of the camera?
|
Mar 3 | 4:30 PM |
Afzal N. |
No, using the accelerometer and gyroscope sensor values
|
Mark M. |
oh, motion of the device, got it
|
Mark M. |
OK, so I'm back to testing the core motion detection logic independently, using some mock source of sensor data
|
Mark M. |
that would be where I would put my efforts
|
Mark M. |
and, if the code for that is implemented nice and clean, you can even test that as plain ordinary Java code, as motion detection itself should not be too Android-specific
|
Afzal N. |
Right, correct. So I wouldn't need Robolectric or anything for those tests then
|
Mark M. |
right
|
EGHDK | has entered the room |
Afzal N. |
And this test would use the motion detection logic directly, not utilizing the whole library to feed sensor data?
|
Mark M. |
well, it's tough to do reproducible tests with real sensors
|
Mark M. |
(BTW, hello, EGHDK -- I will be with you shortly!)
|
Mark M. |
so you'll want mock data
|
Mark M. |
whether the library itself incorporates that for other reasons, or you're mocking it using one of the mocking libraries, or whatever, would tend to depend upon your code
|
Afzal N. |
Right, makes sense. I see. I'll work on writing these tests then and see what other questions I come up with in the process
|
Afzal N. |
Thanks Mark!
|
Mark M. |
you are very welcome
|
Mark M. |
EGHDK: your turn! do you have a question?
|
Mar 3 | 4:35 PM |
EGHDK |
Hey Mark, 2 questions today. First, I'm using AS 1.1 and I'm trying to learn how to test my app.
|
EGHDK |
The first tests I want to create have nothing to do with Android. I want just simple Junit tests.
|
EGHDK |
I have a shape class and a constructor, and I want to assert that contructing a new shape with a size param of 0, throws illegalArgException
|
EGHDK |
Anyway, I'm in my shape class, and I try to create a Test in AS. I select JUNIT4, but it says its not available.
|
EGHDK |
Actually "Junit 4 library not found in the module"
|
Mark M. |
what specifically do you mean by "I try to create a Test in AS"?
|
EGHDK |
That's what is throwing me off now, because junit3 doesn't complain about that.
|
Mark M. |
what specifically do you mean by "I try to create a Test in AS"?
|
EGHDK |
I found a command online for tests. cmd+shift+t
|
Mar 3 | 4:40 PM |
tinoper | has left the room |
Mark M. |
I have no idea what that does, sorry
|
EGHDK |
It does "Navigate > Test" for you in a shortcut
|
Mark M. |
OK, when you got the dialog with the "library not found in module", did you click the Fix button?
|
EGHDK |
IntelliJ docs say that Navigate > Test will take you to the testClass of your class.
|
EGHDK |
But since theres no test... it allows me to create one.
|
Mark M. |
right, and when you got the dialog with the "library not found in module" message, did you click the "Fix" button to the right of that message?
|
EGHDK |
Yeah.
|
Mark M. |
that seemed to make AS happy when I just tried it, though I haven't the faintest idea what it actually changed
|
EGHDK |
So that seems to work fine, but why does junit3 not complain. I never added junit3?
|
Mark M. |
well, the Android SDK has JUnit3 baked in
|
Mark M. |
JUnit4 comes from the AndroidJUnitRunner
|
Mark M. |
I have a chapter on JUnit4 in the book
|
EGHDK |
And also, my question really is... if I want to unit test plain Java classes... should that be the way to do it?
|
Mar 3 | 4:45 PM |
Mark M. |
well, JUnit3 vs. JUnit4 is up to you
|
Mark M. |
the fact that they are plain Java classes would not really impact that decision
|
Mark M. |
it's not like JUnit3 can't test plain Java classes
|
tinoper | has entered the room |
EGHDK |
Okay, yeah I'm just really unsure where to start with testing, especially since now there was something added that made tests... easier/faster?
|
EGHDK |
in AS 1.1
|
Mark M. |
um, you might be referring to the new "unit testing" thing that I haven't peeked at yet
|
Mark M. |
based on comments I have seen, my guess is that it is a little rough around the edges
|
tinoper |
Sorry,I left the room before(Internet problem). Thanks for your advice.Have a nice day
|
Mark M. | |
EGHDK |
Gotcha. Yeah, before I do that, I just wanna unit test my plain java classes. I think thatd be cool and a good place to start while everything else gets ironed out.
|
Mark M. |
tinoper: no problem!
|
EGHDK |
Thanks, you can go to the next person.
|
Mark M. |
EGHDK: OK
|
Mark M. |
tinoper: do you have another question?
|
Mark M. |
tinoper: if you come up with another question, let me know
|
Mark M. |
Afzal: do you have another question?
|
Mar 3 | 4:50 PM |
Afzal N. |
Sure. If you want to use Context in your test (say, to initialize the library class), would you use Robolectric or can it just be done using the built-in tools?
|
Afzal N. |
Or should that test be run in a test app on the phone?
|
Mark M. |
well, if you need a real working Context, in the JUnit3 realm, you would use AndroidTestCase, and run the test on a device or emulator
|
Mark M. |
there is a recipe for JUnit4 with AndroidJUnitRunner, getting a Context from the current Instrumentation
|
Mark M. |
that too would be run on a device or emulator
|
Afzal N. |
Got it. Thanks again! I just got the subscription so I'm going through the book right now
|
Mark M. |
if you are not actually using the Context (e.g., you accept it as input and pass it along to other stuff without calling methods on it yourself), I think Robolectric is an option for you
|
Mark M. |
personally, I haven't used Robolectric
|
Afzal N. |
Hmm I understand now
|
Mark M. |
there are limits to what the Robolectric mocks and stubs can do for you, since they're mocks and stubs :-)
|
Mark M. |
EGHDK: did you have a second question?
|
EGHDK |
Second question. I know this is probably a stretch. How would I hook up a specific action (button click in my case) to a UI of some sort on my dev machine. Basically, right now I want to know when a button has been clicked, so I log it. WOrks fine, but I started logging all of my buttons clicks and now my logcat is filled with them, clutters my actual debug information. I would love if there was a way to notifiy my dev machine of something that I would normally do in a log, but not have it actually show in logcat. Yes, I know filtering exists, but I was wondering if anything else crosses you mind.
|
Mar 3 | 4:55 PM |
Mark M. |
well, there's no channel for that built into Android
|
Mark M. |
there's nothing stopping you from writing some sort of server that runs on your developer machine, and having code in your device/emulator call that server
|
Mark M. |
or, you could just log to something other than LogCat
|
EGHDK |
Gotcha. SOunds complex. Ill probably stick to logcat.
|
Mark M. |
there are lots of Java logging libraries, and some work on Android
|
Mark M. |
they can log to a file
|
Mark M. |
which won't have the rest of the LogCat clutter
|
EGHDK |
Interesting. Alright.
|
Mark M. |
tinoper, EGHDK: in case you missed the announcement, Version 6.5 of the book was released yesterday, so feel free to download your copy
|
EGHDK |
Great. Next v to be out in April?
|
Mark M. |
Afzal: since you subscribed today, you're starting with 6.5 and will get updates for a year
|
Mark M. |
EGHDK: it should be the second half of April, yes
|
EGHDK |
Any idea on what will be going into the April version?
|
Mark M. |
I think the "tentpole" chapter will be (finally) one on tasks, the back stack, recent-tasks list, etc.
|
Mark M. |
I've been putting that off for far too long
|
Mar 3 | 5:00 PM |
Afzal N. |
Yeah! Another update in April. That's actually great, you get multiple API versions in a year.
|
Mar 3 | 5:00 PM |
tinoper | has left the room |
EGHDK |
Also, on version differences, I know you have some kind of changelog, but you don't have like a git diff of the changes right? Like what was actually added and removed?
|
Mark M. |
Afzal: yes, which is why I'm hedging a bit on the late April timeframe, as we are then getting close to Google I|O
|
Mark M. |
and who knows when Google might release something that forces me to adjust my release schedule :-)
|
Mark M. |
EGHDK: the changebars (vertical bars on the outside page edge) show new and changed paragraphs
|
Mark M. |
there's nothing for deletions, though
|
EGHDK |
in the pdf?
|
Mark M. |
yes
|
EGHDK |
I'm not sure what you mean by change bars... lol
|
EGHDK |
Okay I'll look for them
|
EGHDK |
You have my vote on back stack and recents. Still don't get it.
|
Mark M. |
and that's a wrap for today's chat
|
Mark M. |
the transcript will be posted to http://commonsware.com/office-hours/ shortly
|
Mark M. |
the next chat is tomorrow at 7:30pm US Eastern
|
Mark M. |
have a pleasant day!
|
Afzal N. |
You too. thanks!
|
EGHDK |
thanks
|
Afzal N. | has left the room |
EGHDK | has left the room |
Mark M. | turned off guest access |