Office Hours — Today, September 18

Thursday, September 13

Mark M.
has entered the room
Mark M.
turned on guest access
Sep 18
7:40 PM
Parth M.
has entered the room
Parth M.
Hey Mr. Murphy I finally got around to creating a warescription, how exactly does this work?
Mark M.
howdy, Parth!
how can I help you today?
(and I do not know what "this" is to be able to tell you how it works)
Parth M.
So I took your advice on creating a Meetup account, I was wondering what kind of "meetups" I should be going to.
7:45 PM
Mark M.
um, whatever ones are near you that are of interest, I suppose
I am not completely clear on how this relates to Android application development
Parth M.
View paste
Ok, was just a general question.
Anyways. I want to display a large number of bitmaps in a custom view that is nested inside a scrollview. I can put about half of them in memory before receiving an oom error. What should I do?
Mark M.
you probably need to rethink your strategy
there is no point in putting bitmaps in memory that cannot be seen
so, assuming that you cannot reduce the number and/or size of the bitmaps, you will have to not load them all
which means you will probably need to either handle the scrolling yourself (vs. using ScrollView) or trying to rework your presentation model to fit an AdapterView pattern
7:50 PM
Mark M.
for example, games with maps that are bigger than the screen use map tiles, so that they do not have to try to hold the entire map in heap space
Parth M.
View paste
Oh, I never thought about it that way. Currently I have an array of bitmaps with 180 items. What is using my memory? The SHADE_PIC[0] = BitmapFactory.decodeResource(c.getResources(),
					R.drawable.shades_hottie);
or
View paste
for (int i = 0; i < 4; i++) {
				canvas.drawBitmap(SHADE_PIC[i], null, rect[i], null);
			}
Mark M.
if you run your code on Android 3.0+, dump your heap, and use MAT to inspect the heap, you will know what is using your memory
most likely, it is the bitmaps
but that's just an educated guess
Parth M.
What is MAT?
Mark M.
MAT is the Memory Analysis Tool, an add-on for Eclipse that can inspect a heap dump, so you can see what's all being held onto in the heap
there is a chapter on it in _The Busy Coder's Guide to Android Development_
Parth M.
Ok I'll take a look at that. If we assume that the bitmaps are using up my memory, can I create an integer array to hold the resource ID, and and have one bitmap object
7:55 PM
Mark M.
well, you will need a Bitmap object for every Bitmap that is presently on the screen
and, with your ScrollView approach, you will presumably need one Bitmap object for every Bitmap that you intend to have on the screen if the user scrolls
that's why I am advocating that you find a way to avoid using ScrollView
Parth M.
I see, ok, I'll try all of that and tell you how it goes, thanks!
8:00 PM
Mark M.
if you have another question, feel free to ask -- the chat room is not exactly crowded :-)
Parth M.
haha, sure, although It's not really android app dev related
Mark M.
alas, that is pretty much the focus of this chat room
Parth M.
alright, I do have a java related concern
Mark M.
OK
Parth M.
I would like to upload a file, but It contains information about shades that I'm not supposed to release
8:05 PM
Mark M.
do you mean you want to upload a file into the chat room, or you want to upload a file as part of your Android app?
Parth M.
to the chat room, should I just try to explain it using pseudo code?
Mark M.
that's probably best, as this chat room is semi-public
Parth M.
Ok so I have an activity that receives an RGB value (3 integers) from an activity before it. The activity before it gets these values frome the Bitmap.getPixel() method, but that's not really Important. The values enter like so:
View paste
		Bundle bundle = getIntent().getExtras();

		r = bundle.getInt("r");
		g = bundle.getInt("g");
		b = bundle.getInt("b");
Ryan H.
has entered the room
Mark M.
(howdy, Ryan -- I'll be with you shortly)
Parth M.
View paste
I have 2 arrays, a 2d integer array, and a string array.
	static final int COLORS[][] = new int[180][3];
	static final String NAMES[] = new String[180];
Ryan H.
Thanks Mark
8:10 PM
Parth M.
then my algorithm sorts through the integer array to find 20 of the closest shades from the input, like so:
View paste (26 more lines)

		while (!matchesComplete) {

			if (i > 179) {
				i = 0;
				allowance += 1;
			}

			if (((r > (COLORS[i][0] - allowance)) && (r < (COLORS[i][0] + allowance)))
					&& ((g > (COLORS[i][1] - allowance)) && (g < (COLORS[i][1] + allowance)))
					&& (b > (COLORS[i][2] - allowance))
					&& (b < (COLORS[i][2] + allowance))) {
				if (matchPlace >= matches.length) {
					matchesComplete = true;
					break;
...
is there a better way to go about this>
*this?
Mark M.
since I do not completely understand your algorithm, I cannot really answer that
Parth M.
Is there anything I can clarify?
Mark M.
probably not in the scope of what can fit in the chat room
if "closest shades from the input" means smallest R/G/B deltas...
...then I think you have to examine all 180 items, compute that delta, then find the 20 lowest delta values
Parth M.
yes it does, sorry my code is quite unreadable
8:15 PM
Parth M.
View paste
Ok, ill give every thing a shot. Thanks for the help!
(Sorry to keep you waiting Ryan)
Mark M.
Ryan: do you have a question?
Ryan H.
Hi Mark. A simple one. I have an app with multiple activities that bind to a service with a Binder. In my service I track the clients
When the top level activity hits onDestroy when the screen rotates, my service gets restarted
ie, during that point there are no bound activities.
Can I bind the service to Application?
Mark M.
well, you can use the Application context to bind to the service, if that's what you mean
Parth M.
has left the room
Ryan H.
Yes
Mark M.
I think I demonstrate that in my binding coverage
in the book
Ryan H.
Will that cause any problems?
Mark M.
well, you will need to both bind and unbind using the same Context, so you have to remember to use Application in both places
beyond that, I am not aware of any particular problems (e.g., memory leaks) that this might cause
Ryan H.
OK. I'll try that then.
Mark M.
hmmm... I may have lost the sample I was thinking of as part of this year's Big Book Reboot...
here it is from an older edition: https://github.com/commonsguy/cw-android/t…
8:20 PM
Ryan H.
Thanks. Of course if the service binding returns the service, anything I do with the service happens on the UI thread
Mark M.
not exactly
activities are perfectly capable of using background threads, like an AsyncTask
services are in the background from a UI standpoint
they are not automatically in the background from a threading standpoint
but that is true for both the binding pattern and the command pattern
Ryan H.
OK. I'm putting my DB writes in AsyncTasks, and DB reads to update views in Loaders and it seems to be working OK
Mark M.
that sounds reasonable
Ryan H.
Alright, I didn't have many questions, just came to watch
Mark M.
alas, not much watching going on today
Ryan H.
Have a good week
Mark M.
you too!
8:30 PM
Mark M.
that's a wrap for today's chat
next one is tomorrow, also at 7:30pm Eastern
have a pleasant day!
Ryan H.
has left the room
Mark M.
turned off guest access

Thursday, September 13

 

Office Hours

People in this transcript

  • Mark Murphy
  • Parth Mehrotra
  • Ryan H