Office Hours — Today, November 9

Tuesday, November 2

Nov 9
4:05 PM
Mark M.
has entered the room
Mark M.
turned on guest access
Suzanne A.
has entered the room
Prasanna P.
has entered the room
Prasanna P.
Hi Mark
Mark M.
hi!
sorry I'm late
Suzanne A.
Hi Mark and Prasanna
Mark M.
my Google Calendar reminder must be broken for this calendar entry
:-(
OK, ladies first...Suzanne: how can I help you?
Prasanna P.
no problem
Suzanne A.
Can we ask general Android development questions here?
Mark M.
absolutely!
Suzanne A.
I have a list of questions ..
Mark M.
If we could do one at a time, then give others a shot, that'd be great
Suzanne A.
View paste
First, what is the best way to resize and scale an image dynamically at runtime,
for device density, considering memory and performance?
Ales
has entered the room
Mark M.
howdy, Ales!
Suzanne: I'm not aware there is more than one option
Octavian D.
has entered the room
Ales
Hello
4:10 PM
Suzanne A.
Is it BitmapFactory.Options, followed by Bitmap.createScaledBitmap?
Mark M.
right
Octavian D.
hello
Mark M.
I'm fairly certain everything else (e.g., the scale options on ImageView) all route to the same core logic
howdy, Octavian!
Suzanne A.
ok, thanks
Mark M.
we'll get back to your next question in a bit...
next up, Prasanna -- do you have a question?
Prasanna P.
i am showing a dialog on my ui thread. I want to get rid of this dialog on my onPause()
as I do not want it to show up when the app ...
is started again if the user did not
click on 'OK" to get rid of the dialog
so how do i check to see
if it is was shown and
the user did not click 'ok' on it
Mark M.
um, that's up to you
Prasanna P.
and if it is still there to get rid of it
so how can i check to see if a dialog is still showing
Mark M.
AFAIK, it is safe to dismiss a dialog that is not showing, so you can probably call that blindly
Jay M.
has entered the room
Prasanna P.
so i can always dismiss a dialog
Mark M.
I think so
Prasanna P.
on my onStop method?
Mark M.
beyond that, use a boolean data member
you get control on every button click
so you can track your state yourself
Darryl
has entered the room
Prasanna P.
ok
thanks!
Mark M.
it would be nice if there were an isDialogShowing() method for the managed dialog system, but it doesn't appear there is
OK...next up, Ales: do you have a question?
Ales
I have a problem with ANR. Not sure where to start looking for possible problems
Prasanna P.
fyi. no more qs from me ... so just handing out ...
Ales
Activity starts and display a list of items
4:15 PM
Ales
but i can't check checkboxes
4:15 PM
Ales
until that message pops up
Application not responding...
Mark M.
OK, it is rather difficult to provide assistance on this sort of question via a chat
you are doing something that is taking too long on the main application thread
what that is, I can't say
Julius
has entered the room
Ales
The only thing i do is get like 5 or 6 items from database and that is all
If I attach log, do you think you can see a problem?
Mark M.
I doubt it
it's been a while since I've looked at an ANR log
but IIRC, it does not exactly say where you are being tied up
do you see any of your code in the stack trace?
Ales
I'm not realy familiar with that trace
It is interesting though
Mark M.
OK, my recommendation is for you to set up an account on StackOverflow and open up a question about this, posting your code and the stack trace
Ales
When i start application it works fine, but if i switch a few of my activities this happens
Ok, i'll try there
Mark M.
wait a minute, you said that "Activity starts and display a list of items but i can't check checkboxes until that message pops up"
4:20 PM
Ales
correct
Mark M.
now you're saying it works, but you have to click around other activities?
which is it?
Ales
list is always populated
but sometimes can't check checkboxes for a while
after that message .. i click wait and it works fine from then
Mark M.
OK, this is definitely something beyond what a chat can resolve
I'm not even sure if StackOverflow can help
you need to narrow down the source of your difficulty, perhaps by commenting things out, or determining the precise set of events that causes you to consume too much time on the main application thread
Octavian, do you have a question?
Octavian D.
nope, just lurking
Ales
Could something like this happen if I use ArrayAdapter instead of CursorAdapter?
Mark M.
Ales: your choice of adapter should not cause an ANR
Jay, do you have a question?
Jay M.
View paste
Yes, I've pre-typed and am ready to go:

I'm using WakefulIntentService.  

My first question, if I set private variables in my WakefulIntentService class, I can't rely those values to be there when the AlarmManager triggers because the thread may be gone and get re-created, correct?  I know this because everything is fine when the interval is short, but if it's a longer interval things go wrong.  Am I on the right track?  

If so, is SQLite the way to go for persisting three or four values for a WakefulIntentService, or are there other options?
Mark M.
on your first question, yes, instance and static data members may both be gone by the time the service starts up again
on your second question, SQLite or a flat file are likely candidates
it has to be in file storage
if there are no other components of your application running, Android may recycle or terminate your process, taking any in-RAM objects with it
4:25 PM
Mark M.
Darryl, do you have a question?
Jay M.
Ok - good to know I'm in the right direction. Thanks for the awesome resources!
Darryl
Hello, thanks once again for taking the time to help us out. I was wondering a little about networking. I am running Android 2.2 on my Nexus One. I would like to be able to enable the portable hotspot (which doesn't have to be programmatically) then connect other devices to the hotspot (another android phone, an iPad, whatever). Now, from my Nexus One, I would like to be able to know what devices are connected to the hotspot, as well as be able to transfer files to those devices (or request a file transfer from my Nexus to one of the devices). Now, I have been able to connect two devices via Bluetooth and transfer data that way, but I would like to connect more than two devices (and maybe an i-device) at the same time. So the bottom line question: is there a way to see what devices are connected to the hotspot and communicate with devices which are connected? If so, how would I go about doing that? I know there is wifiManager, but that doesn't seem to be enough.
Mark M.
Nothing about the WiFi hotspot is in the SDK at this time
We'll see if they add anything in Gingerbread
Darryl
Darn.
Thanks!
Mark M.
yeah, it'd be nice to do more with it -- my guess is that they aren't comfortable with the API just yet
Julius, do you have a question?
Julius
yes
hi
3
one at a time
View paste
I have an application which needs to be deployed twice with different branding for each.  Is there a way to manage the code so if I make changes in the future they will stick across multiple versions? (I can only think of using SVN)
it's really just image branding and maybe package naming
Mark M.
sounds like an Android library project for the core, and application projects for the rest
you could play some games with version control scripts, but they make me nervous
take a look at Android library projects and see if that fits your needs
Julius
ok thanks
Mark M.
we'll swing back for your other questions in a bit
Julius
of course thank you
Mark M.
back to the top -- Suzanne, do you have another question from your list?
Suzanne A.
I need to download a batch of images from a web server, once a day, each with some text metadata. Can I download a zip or jar file using HttpClient and unpack it?
Mark M.
sure
java.util.zip is in the SDK
brack
has entered the room
Mark M.
as is java.util.jar
though I'd probably just use a ZIP file
Suzanne A.
And since I need metadata for each image, what's the best way to store the data?
Mark M.
I like ASCII -- better support for that than EBCDIC in Android
:-)
(mainframe joke for you young'uns on the chat)
4:30 PM
Mark M.
beyond that: XML, JSON, ...
4:30 PM
Mark M.
take your pick
Suzanne A.
On the device - in a content provider?
Mark M.
you lost me there
where's a content provider come into the download-a-ZIP-file picture?
Suzanne A.
If I download a zip and unpack it on the device, I have a batch of images, each with text
Darryl
has left the room
Suzanne A.
And I need to match each image to its text, for display
Mark M.
you can use a content provider, or a database, or just a Java class
that's really up to you
Suzanne A.
whichever I choose?
ok
Mark M.
it's not like content providers are somehow magical for daily downloads of ZIP files of images and metadata
OK, brack did not get a chance just yet -- brack, do you have a question?
4:35 PM
brack
yes, mainly about views and programmatically adding views into layouts
basically i'm attempting to integrate an admob adview into a view that has a listview. optimally, when an ad becomes available, I'd like to shrink the table, and fade/slide in the ad
Mark M.
by "the table" do you mean the ListView?
brack
i've messed around a bit with making the xml-defined ad slot visibility=gone, and changing the visibility in the code, but the listview never updates
yep
i have a ListActivity
NetApex
has entered the room
Mark M.
you can see this pattern in _Android Programming Tutorials_
I use it for hiding/showing the status update widgets in Patchy
check out Tutorial 26
I use an animation there as well, fading in/out in my case
brack
roger; I probably should have checked that first, sorry about that.
Jay M.
has left the room
brack
oh great, yeah i'll definitely check that out
Mark M.
though you could use an AnimationSet to do both a fade and a slide
OK...this is one busy chat today
brack
Oo fancy, I dig it. thanks, i appreciate it!
Mark M.
NetApex, you haven't had a chance yet -- do you have a question?
NetApex
Nothing at the moment
Mark M.
Prasanna said he was just lurking, so...Ales, do you have another question?
Ales
Can I access ImageView of another activity within other activity using findViewById or something?
Mark M.
not really
what are you trying to achieve?
4:40 PM
Ales
setImageResource
but ok can be done another way i guess
using Thread
Mark M.
arbitrary inter-activity communication is not typical
you pass data via startActivity(), and you can get data back via startActivityForResult()
Ales
ok
Mark M.
otherwise, the activities should be independent
just as one Web page cannot update another Web page of a Web app
Ales
It's actually a service
Mark M.
You asked, "can I access ImageView of another activity within other activity"
now, one of those activities has turned into a service?
regardless...
Ales
Is there a difference in this case
Mark M.
yes
Ales
oh i see
Mark M.
a service still cannot, and should not, be updating widgets
however, there are more options for services to notify activities about changed data
Ales
So the best thing is to create a Thread from main activity and use handler?
Mark M.
callback/listener objects, createPendingIntent(), broadcast Intents, etc.
Um, threads have nothing to do with your question
where and when you need threads is a completely different topic
4:45 PM
Mark M.
I will have a revamped set of chapters covering services in the next update to _The Busy Coder's Guide to Android Development_
Ales
I just want to change image when service completes a taks that is all
Mark M.
that will hopefully answer your questions here a bit better
you assume your activity is still there, which may or may not be the case
the new chapters will demonstrate some solid service patterns that perhaps you can follow
Ales
It will since it's root activity
Mark M.
anyway, that update to the book will be out in the next couple of weeks, dependent a bit on when that loaf of Gingerbread arrives
Julius: do you have another question?
Julius
yes
View paste
I have an application which uses a Camera application to take a photo as such: 
Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
i.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(fwyPhotoRoot, filename)));
startActivityForResult(i, VIEW_TAKE_PHOTO);
In doing this a full sized photo should be store in the location provide. The problem is that the photo is not full sized but scaled down. It would appear to be the same problem as noted here:
http://code.google.com/p/android/issues/detail?id=1480#c10
Just wondering if you've come across this and maybe have a slick solution. I don't want to write a full Camera app (I looked at the source code for Camera). I'm also creating videos from the camera and would like to know how to create a thumbnail from an mp4 file… (oh on 1.6 unfortunately)
store => stored provide => provided
Mark M.
I have not used ACTION_IMAGE_CAPTURE
I have not used MediaRecorder for video capture
Julius
ok... I have another question...
I have an application which has a button which takes the user to a form in the web browser (from a web server on the Internet). When the user has filled in the form (account creation) he is sent back into the application by the web form. The application then takes data from the Intent in the onResume and logs the user in. This works very nicely. However, if the user hits the Home key and then selects the application it appears that a new instance of the application is started as the user is no longer "logged in".
Mark M.
a basic activity to take a picture is < 100 lines of code
profiled in two of my books
Julius
yes I trie, that but ran into all sorts of problems with landscape and portrait...
Mark M.
where is your "logged in" status stored?
Julius
it's in the Shared Prefrerences
4:50 PM
Mark M.
um, really?
in that case, I have no explanation for your problem
Julius
sorta
Mark M.
you only have one set of SharedPreferences
Julius
I mean yes
it's not ideal but yes
yes just one
Mark M.
you must not be reading in the SharedPreferences the way you are thinking of
Julius
it feels like another instance of the application is starting
Mark M.
or perhaps you're not commit()-ing when you store it or something
Julius
right
Mark M.
doesn't matter
Julius
yeah I checked that too :)
Mark M.
you only have one set of SharedPreferences
Julius
I'll just have to breakpoint some more
yes
Mark M.
sorry
Julius
I have an application with two
Mark M.
Suzanne: do you have another question?
Suzanne A.
On my earlier question, about BitmapFactory.Options and Bitmap.createScaledBitmap. Does doing this programmatically in an app, as opposed to letting Android scale images automatically, help prevent OutOfMemory errors? Or not, if both access the same code in Android?
Julius
in fact two apps with two SharedPrefs but this one only needs one
np
thank you
Mark M.
um
I suspect that you have finer-grained control over things if you do the scaling yourself
Julius
has left the room
Suzanne A.
okay ..
Mark M.
but your question is difficult to answer in the abstract
it's all about how many images, how you're using them, etc.
Suzanne A.
right
Mark M.
Ales: do you have another question?
Ales
So to go a bit further with my last question
Let's say i want to create a kind of progress icon
4:55 PM
Ales
If user clicks this icon, method starts in service
While this method runs i would like to show "active" icon until it finishes
What would be the best way
Mark M.
I can't really say what is "best" just based on this information
when you say "method starts in service" what do you mean?
Ales
Let's say you have wheather app and refresh icon
while service is parsing data from web server I would like to have "active" icon in my main activity.
Suzanne A.
has left the room
Mark M.
let's try this again
when you say "method starts in service" what do you mean?
did you call bindService() and are now literally calling a method on the Service object itself?
or do you mean something else entirely?
Ales
I call a method service.getWeatherInfo()
Yes i do bind service before that
Mark M.
OK
then, one (may or may not be "best") solution is to use a callback or listener object
5:00 PM
Mark M.
your call to getWeatherInfo() passes an object to the service
5:00 PM
Mark M.
when the service is done getting the weather, it calls a method on that object
use that to have your service asynchronously notify the activity of the results of the work
which, among other things, can change your icon
Ales
oh i see
Mark M.
in the current edition of _The Busy Coder's Guide to Android Development_, I show using a broadcast Intent for this, which also works, but the callback is more efficient and private
you will see the callback approach used in _Android Programming Tutorials_, in the Patchy samples
Ales
You see ... here is why i used thread and handler to get info back
Mark M.
Tutorial 18 and 19, specifically
Ales
Did not not what else to do
Mark M.
well, like I said, the books have examples of ways of doing it
and, the next update to the original Busy Coder's Guide will have more patterns as well
Ales
thank you
Mark M.
OK, anyone have a last question before we wrap up the chat?
brack
yeah if you have a minute
three things, really: just a point in the right direction would be great
1) resizing an image: anything i should search on specifically? is there a tutorial already in your book?
5:05 PM
Mark M.
nothing in the books, check earlier in this chat for discussion of it, and see BitmapFactory
brack
2) my ongoing notification for my service isn't a marquee (ie text too big, doesn't scroll). should it scroll?
ok cool, will check bitmapfactory
Mark M.
you lost me on 2)
brack
sorry, meant to say: should it scroll automatically, or do i have to set a flag?
Mark M.
do you mean a real Notification?
brack
yeah
Mark M.
if so, it's an icon, not text
what text?
brack
hm, perhaps we missed eachother on the Notification thing. i'm referencing the top-tray notification area that allows custom views, etc
i'm not taking advantage of a custom view currently. i'm using Notification with text
View paste

Notification note = new Notification(R.drawable.playbackstart, text, System.currentTimeMillis());
        note.flags |= Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT;
        note.tickerText = text;
Mark M.
right
that text appears briefly when the Notification is first added
it is on screen for 1-2 seconds
brack
tickerText doesn't seem to do anything
Mark M.
sure it does
check out Notification/Notify1 sample from _The Busy Coder's Guide to Android Development_
brack
ah, it ticks when it pops on screen? i didn't notice. i'm mainly trying to get the system tray one to work
ok cool
will definiteyl check that out
Mark M.
yeah, it is only there just for a moment
brack
last one: marquee for a textview
Mark M.
what about it?
brack
can't seem to get this to work... maybe i should paste code, or perhaps you already have a tutorial
Mark M.
the effect only appears if the TextView is in the selected state
or its parent is in the selected state
5:10 PM
brack
right, i had indeed read that at some point
Mark M.
for example, if you try the Fancy/DynamicTab sample and add a whole mess of tabs, you will see the selected tab's caption do the marquee thing twice
brack
which means the user must have had to interact with it to have it be scrolling
Mark M.
yeah, otherwise if you used it a lot, the screen would be way too busy
brack
ah- what would "selected" mean
user selected? or can i specify my textview as selected
Mark M.
in the case of tabs, it's the selected tab
you can try setSelected()
that might have side effects
haven't tried it
brack
alright, will try that. i had it working for a brief period, and eventually it broke. wasn't sure if there was a specific trick to getting the text scrolling properly
Mark M.
it probably just got stuck -- try WD-40
:-(
brack
and by had it working, i mean it was defined in XML and when the view loaded, it would make the text ticking as expected
haha
Mark M.
er, :-)
ok, that's it for today's chat
Octavian D.
thanks Mark, good night
brack
great, thanks a ton Mark. appreciate it; good night
Mark M.
have a pleasant day, everyone!
Prasanna P.
has left the room
brack
you as well!
Ales
has left the room
Octavian D.
has left the room
brack
has left the room
NetApex
has left the room
Mark M.
turned off guest access

Tuesday, November 2

 

Office Hours

People in this transcript

  • Ales
  • brack
  • Darryl
  • Jay Muntz
  • Julius
  • Mark Murphy
  • NetApex
  • Octavian Damiean
  • Prasanna Perera
  • Suzanne Alexandra