Office Hours — Today, July 3

Thursday, June 28

Jul 3
3:55 PM
Mark M.
has entered the room
Mark M.
turned on guest access
4:00 PM
Alexander B.
has entered the room
Alexander B.
hi
Mark M.
howdy, Alexander
how can I help you today?
Alexander B.
I am trying to get my database to work on the real device
Bruce F.
has entered the room
Alexander B.
I was following an example
but it just doesnt seem to work
Mark M.
um, could you clarify a bit on "doesnt seem to work">
(BTW, howdy, Bruce!)
Bruce F.
Hi Mark.
Alexander B.
ok well i get a null pointer exception
Frank S.
has entered the room
Alexander B.
it doesnt seem to be able to find the file
this is the code it uses
Mark M.
what is "the file"?
Alexander B.
View paste (4 more lines)
try {        	
            	
            	String destPath = "/data/data/" + getPackageName() + "/databases/MyDB";
            	File f = new File(destPath);        	
            	if (!f.exists()) {        	
            		// change what is being passed 
            		
            		// so this code need to be fixed output the path
            		
            		
            		
    			    CopyDB( getBaseContext().getAssets().open("mydb"), 
    					new FileOutputStream(destPath));
            	}
    		} catch (FileNotFoundException e) {			
...
Mark M.
(BTW, howdy, Frank!)
Frank S.
hi
Mark M.
that's fairly unpleasant code
Alexander B.
i know
Mark M.
I take it your objective is to package a database with your app -- is that correct?
Alexander B.
yes
i took that example from a book
Mark M.
I recommend SQLiteAssetHelper: https://github.com/jgilfelt/android-sqlite…
4:05 PM
Mark M.
you will find coverage of this in _The Busy Coder's Guide to Advanced Android Development_, and the 0.8 version of the Omnibus
this would replace all the code you have above, and it has been fairly well tested at this point
Alexander B.
thats great
thats great
Mark M.
let me take some questions from the others, and I'll come back to you in a bit
Bruce: do you have a question?
Alexander B.
offcourse
Bruce F.
sdk tools rev 20 breaks Sherlock project. Suggestions?
Mark M.
it isn't breaking any of mine -- can you be more specific?
Bruce F.
conflict with support library versioning
View paste
Found 2 versions of android-support-v4.jar in the dependency list,
not all the versions are identical (check is based on SHA-1 only at this time).All versions of the libraries must be the same at this time.
Mark W.
has entered the room
Mark M.
then synchronize your projects
either upgrade ABS to use the newer library or downgrade your app to use the older one
R20 does not really care either way, other than perhaps when it initially sets up a new project with the new template stuff
(BTW, howdy, Mark!)
Bruce F.
I upgrade abk how?
Mark W.
hi
Bruce F.
abs that is
Mark M.
copy the android-support-v4.jar into libs/, the same as you would for any other project
it already has one
Bruce F.
thank you
Mark M.
Frank: do you have a question?
Frank S.
View paste (7 more lines)
I'm having major problems getting Unit Tests done the way AOSP has it.
I want to have a the test project in the same directory as the main project so I run this command

android create test-project -m ../ -p ROAMpayX/tests -n ROAMPayTest
cd tests
ant debug
adb install bin/RoamPayTest-debug.apk
adb shell am instrument -w -e class com.roamdata.roampayx.ui.SplashActivityTest com.roamdata.roampayx.tests/android.test.InstrumentationTestRunner

junit.framework.TestSuite$1:
Failure in warning:
junit.framework.AssertionFailedError: No tests found in com.roamdata.roampayx.ui.SplashActivityTest
	at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:190)
	at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:175)
	at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:555)
...
Tom O.
has entered the room
4:10 PM
Tom O.
A hoy hoy
Mark M.
View paste
your test APK is in ROAMpayX/tests/bin, not tests/bin
(howdy, Tom!)
Frank S.
yes
Mark M.
but your console paste has you in tests/bin
that directory should not exist
you start in directory $FOO
you create your test project in $FOO/ROAMpayX/tests
you change into $FOO/tests
and try running tests from $FOO/tests/bin
admittedly, I am rusty on the test setup process, so maybe I am mis-remembering the android create test-project command
Frank S.
That must be a typo. ROAMpayX is the main project and tests/ gets created correctly inside of that
Mark M.
OK
Frank S.
yeah the -m option is relativly to the test project
Mark M.
does SplashActivityTests actually contain test methods?
Frank S.
View paste
    @SmallTest
    public void dummyTest() {
        assertEquals(true, true);
    }
Mark M.
ah
Frank S.
made sure to use import android.test.suitebuilder.annotation.SmallTest;
Mark M.
Android uses JUnit 3 -- no assertion-based tests
um, OK
I have never seen that syntax
on Android, anyway
try using more classic JUnit test method names, like testDummy(), where the test method starts with "test"
Frank S.
that just gave me the @SmallTest
4:15 PM
Mark M.
I have definitely used tests in a tests/ subdirectory of the main project, so that should not be your problem
Frank S.
Mark your the man.
I didn't even realize. I changed dummyTest to testDummy and it worked!
lol
Mark M.
yeah, names matter, particularly in JUnit 3
JUnit 4 and above have a means of declaring them via annotations (BTW, typo in earlier chat message where I said "assertions" rather than "annotations")
anyway, moving along...
Mark: do you have a question?
Mark W.
greeting from China, quick one for you....
looking for approaches to display a sting in a TextView, playing with ViefFlow, ViewPager, etc
Ben K.
has entered the room
Mark W.
variable length string, and need a way to auto create the view, maybe kind of like the Omnibus book example?
Mark M.
sorry, but I am lost
what is ViefFlow?
(BTW, howdy, Ben!)
Ben K.
Hello
Mark W.
ViewPager needs to create views manually, can I create views automatically based on size of the string?
Mark M.
your PagerAdapter can return whatever you want
Mark W.
for example with cirlceindicator, perhaps I need 5 circles and 5 views is the string is a certain length, is that how the book reader example works in omnibus?
Mark M.
if it wants to make decisions based on string length, string contents, string theory, or string cheese, it can certainly do so
4:20 PM
Mark M.
I don't know what the "5 circles and 5 views" are referring to
Mark W.
ok, thanks, that helps Mark, cheers.
Mark M.
the book reader knows the number of chapters based on the count included in the JSON
for each page, it creates an appropriate fragment, though they are all the same fragment in the case of EmPubLite
EmPub itself uses different fragments (e.g., a cover page fragment)
Tom: do you have a question?
Tom O.
Yeah, just a quick one I'm sure.
Say I have a service running in the background (unbound). That services does something of interest to the user. What is the best way to signal the user that something was done?
Mark M.
that depends
if there's no chance that a foreground activity would care, just use a Notification
Tom O.
Say there might be a foreground activity?
Mark M.
if, however, a foreground activity might want to update the user directly, use an ordered broadcasts
I cover this pattern in The Busy Coder's Guide to Advanced Android Development and v0.8 of the Omnibus
Tom O.
So if the foreground activity isn't running anymore, then what happens to the ordered broadcast?
Ah, cool. I shall go check those out.
Mark M.
a BroadcastReceiver in the manifest picks up the broadcast and raises a Notification
the ordering is so the activity can get in first (via priority) and can abort the broadcast (to avoid the Notification)
the nice thing is that the service neither knows nor cares if there is an activity in the foreground that needs the event
4:25 PM
Tom O.
Yes, that is exactly what I'm trying to avoid - some sort of affinity between my service and an activity.
thanks a bunch!
Mark M.
happy to help
Ben: do you have a question?
Ben K.
Yes
Mark M.
go ahead
Ben K.
It's about an exception so I'm not sure to what extent can be helped, but I am using a multithreaded DefaultHttpClient, and on a get I got a socket exception: connection timed out. I was wondering if you know any obvious gotchas.
Mark M.
:: shrug ::
server might not be running, might not have an Internet connection, etc.
Ben K.
I see. Ok, thanks!
Mark M.
that's probably a better question for the HttpClient folk, to enumerate the possible triggers of a timeout
Alexander: do you have another question?
Alexander B.
yes please
i am trying to get the value from a customcursoradapter and return it to the main activity
i can upload the code if it will help
4:30 PM
Mark M.
what is "the value"?
4:30 PM
Alexander B.
the value is an int
Mark M.
um, OK
a custom CursorAdapter is used by an AdapterView, like a ListView
you can call methods like getItem() on the CursorAdapter to get a Cursor positioned on some index
you can then ask that Cursor to retrieve an integer column via getInt(), passing in the index of the column to retrieve
since the custom CursorAdapter is presumably held by the "main activity", that activity would do this work to retrieve your desired int
let me take some questions from the others, and we can follow up in a bit if there is time
Alexander B.
would it help if i showed you some of the code
Mark M.
Alexander: to be honest, probably not in this case
Bruce: do you have another question?
Bruce F.
Yew. Very general question - looking to load a google image into a view. I know it needs to be async. Any other general guidelines or cut and paste code suggestions before I start?
4:35 PM
Mark M.
if by "google image" you mean some Google Images API, I have never used it
you should ponder your caching strategy, to prevent excessive re-downloads of the same image
Bruce F.
just generally downloading an image off the web
Mark M.
beyond that and the async stuff, I have no general recommendations
Bruce F.
thank you
Mark M.
Frank: do you have another question?
Frank S.
View paste
Yes. What is your Theory about ContentProviders with several Tables
Should each tables extend it's own Provider much like ContactsApp
Mark M.
I would phrase it more as "design it like you would design a REST Web service"
Frank S.
Or Helper class that just modify queries and returns
Mark M.
oh, I see
Bruce F.
has left the room
Mark M.
I did not realize that Contacts used separate ContentProvider subclasses -- I thought it only used one
hold on...
Frank S.
Yeah. The helper classes would just use the one provider query and customize it for that table
Mark M.
yeah, Contacts has a few providers, but they are more per-database than per-table
for a single database, multiple tables, a single ContentProvider should suffice
Frank S.
Yeah. We aren't going to have nearly as much code and information as the Contacts
Mark M.
you would use portions of the path after the authority and before the instance ID to identify the table (or virtual table, after doing some joins and such)
Frank S.
so you saying go the helper class route?
Mark M.
yes
or, if you prefer, extend ContentProvider several times, with a composite ContentProvider at the top level
from a manifest standpoint, I'd only have one ContentProvider and one authority for a database
4:40 PM
Frank S.
Ahh. I see. I actually think I may like that route better.
Mark M.
whether you wish to steal the ContentProvider API to implement a composite pattern is up to you
Ben K.
has left the room
Mark M.
though it's possible you'll need to create your own interface that mirrors the ContentProvider API, as you probably cannot instantiate a ContentProvider directly yourself
Mark: do you have another question?
Mark W.
Yes, occasionally get a VM SHUTTING DOWN after my app runs a long time, especially if users switch languages a lot of times- on the fly switcher button. Have been looking at MAT and pretty sure there are no memory or thread leaks. 2.3, but not using drawables. Any causes for Dalvik to Shut down suddenly?
Mark M.
not that I am aware of
other than normal Android process termination
from your description, though, I assume that your app is in the foreground when this happens
Mark W.
yes, in the foreground
thanks mark, appreciate this forum.
Mark M.
yeah, that should not happen
sure, though I am stunned you are making use of it right now -- isn't it pretty early in the morning where you are?
Mark W.
right. all nighter.
Mark M.
ah, sorry to hear that
Tom: do you have another question?
4:45 PM
Mark M.
OK...
Alexander: do you have another question, or a follow-up from your last one?
OK, if anyone has any more questions, chime in
4:50 PM
Frank S.
nope. You killed it today Mark, lol
Tom O.
has left the room
Mark W.
has left the room
4:55 PM
Frank S.
Thanks Mark. Talk to you Thursday
happy 4th
Mark M.
you too!
5:00 PM
Mark M.
OK, that's a wrap for today's chat
next one is Thursday at 10am
have a pleasant day!
Alexander B.
has left the room
Frank S.
has left the room
Mark M.
turned off guest access

Thursday, June 28

 

Office Hours

People in this transcript

  • Alexander Brown
  • Ben Krack
  • Bruce F
  • Frank Sposaro
  • Mark Murphy
  • Mark Wickham
  • Tom Opgenorth