Oct 9 | 7:20 PM |
Mark M. | has entered the room |
Mark M. | turned on guest access |
Oct 9 | 7:25 PM |
Gabriele | has entered the room |
Mark M. |
howdy, Gabriele!
|
Mark M. |
how can I help you today?
|
Gabriele |
Hi :)
|
Gabriele |
I pastebin some code, just a moment
|
Oct 9 | 7:30 PM |
Gabriele | |
Gabriele |
I'm using a webview inside a pager, it's working
|
Gabriele |
My question is, is my "object oriented" concepct corret? Because to me, it seems that I have too much code in this class
|
Mark M. |
194 lines isn't *that* huge
|
Gabriele |
You're an experienced programmer and probably you
wold move something, but I don't know which is the code the move, if I
have to move
|
Gabriele |
But, private void initializeWebView() is right in this class?
|
Gabriele |
Or it would be better to put these things elsewhere?
|
Mark M. |
well, if you were using fragments, all of that would be in the fragment
|
Mark M. |
and your PagerAdapter would be a FragmentPagerAdapter and therefore already a bit simpler
|
Mark M. |
however, I am assuming that you are intentionally
avoiding fragments here (e.g., you want the ViewPager itself to be in a
fragment)
|
Pedro T. | has entered the room |
Gabriele |
Yes, I've found some difficult using my first pager, so I thought it was better to not use fragments
|
Mark M. |
you could create some sort of WebViewHelper class that handles all of those listener interfaces
|
Mark M. |
and initializeWebView() would create an instance of the WebViewHelper
|
Gabriele |
Ah, so a class WebViewHelper can contains my listeners
|
Mark M. |
(BTW, howdy, Pedro -- I will be with you shortly)
|
Mark M. |
Gabriele: right
|
Oct 9 | 7:35 PM |
Mark M. |
since those listeners are mostly interfaces,
WebViewHelper could implement the interfaces directly on itself, rather
than using a bunch of anonymous inner classes
|
Mark M. |
however, WebViewClient is not an interface, so your WebViewHelper would probably extend WebViewClient
|
Mark M. |
that might be worth the effort
|
Mark M. |
but, in the end, it does not matter how many lines of code are in a file
|
Mark M. |
what matters is whether or not you will understand what you wrote, three months from now :-)
|
Gabriele |
I see. It wasn't for the number of lines, but
becase I was scared of "how" my code was written. Am irespecting object
oriented paradigm? This was the mainly reason. :P
|
Mark M. |
unless this is a college homework assignment, I
would worry less about "object oriented paradigm" and more on whether
you understand the code
|
Mark M. |
let me take a question from Pedro, and I'll come back to you in a bit
|
Mark M. |
Pedro: do you have a question?
|
Pedro T. |
Yes
|
Gabriele |
Yes, sure.
|
Pedro T. |
I still trying to solve why is my app with a heap
|
Pedro T. |
so In fact the cache
|
Pedro T. |
of the resources
|
Pedro T. |
is taking to much spaces
|
Pedro T. |
space
|
Pedro T. |
on the 4x lg hd
|
Pedro T. |
also more than the resolution
|
Pedro T. |
the object is being stored uncompressed
|
Oct 9 | 7:40 PM |
Pedro T. |
with 2160X1424
|
Pedro T. |
that is a lot more than the screen resolution
|
Pedro T. |
And also, each button with its respective selector
|
Pedro T. |
is being stored with more resolution than the screen needs
|
Pedro T. |
this also explains, why it crashes on my 4x HD, but doesn't on my old cell phones
|
Pedro T. |
so I was wondering if there is a way to use Recycle
|
Pedro T. |
for my xml bitmaps
|
Pedro T. |
that are not initialized under code
|
Pedro T. |
so after each screen I can free the memory
|
Mark M. |
OK, first I need some clarification on some things that you wrote here that do not make complete sense
|
Pedro T. |
ok
|
Mark M. |
1. "the cache of the resources is taking to much
spaces" -- do you mean Android drawable resources, the kind you would
have in res/drawable-*/ ?
|
Pedro T. |
yes
|
Mark M. |
2. "the object is being stored uncompressed" -- what object?
|
Oct 9 | 7:45 PM |
Pedro T. |
the backgroung image
|
Pedro T. |
and the buttons
|
Pedro T. |
View paste
|
Pedro T. |
there is the layout information
|
Mark M. |
3. "for my xml bitmaps" -- what are "xml bitmaps"?
|
Pedro T. |
drawables used as background that are managed using a selector
|
Mark M. |
OK
|
Mark M. |
an LG Optimus 4X HD should be an -xhdpi device
|
Pedro T. |
yes
|
Mark M. |
do you have a res/drawable-xhdpi/ directory with bitmap files in it?
|
Pedro T. |
yes
|
Mark M. |
do these images include the ones that you are complaining about (background and buttons)?
|
Pedro T. |
yes
|
Mark M. |
what resolution are the images in your project?
|
Pedro T. |
1080 x 760 px
|
Mark M. |
how did you determine that they are 2160X1424 in your heap?
|
Pedro T. |
using MAT
|
Mark M. |
MAT tells you bytes, not resolution
|
Oct 9 | 7:50 PM |
Mark M. |
regardless, to your question, you cannot recycle resources
|
Pedro T. |
Hoooo I thought mHeight and Mwidth were the resolution
|
Pedro T. |
of the object
|
Mark M. |
oh, that may be
|
Pedro T. |
first
|
Mark M. |
I thought you were doing a calculation based upon the amount of heap space the Bitmap object consumed
|
Mark M. |
I do not know why they are being sized 2x in each dimension
|
Mark M. |
but you will need to have fewer/smaller of these resources if that is the source of your difficulty
|
Mark M. |
even 1080x760 is going to take up ~2MB or so of heap space
|
Pedro T. |
exactly
|
Mark M. |
and there is nothing you can do about that, other than to have fewer or smaller of those images
|
Mark M. |
or move some out of resources, where you manually manage the memory yourself
|
Mark M. |
for example, having a 1080x760 button background seems... excessive
|
Pedro T. |
1080 x760 is the screen background
|
Oct 9 | 7:55 PM |
Pedro T. |
the buttons are 260 x74
|
Mark M. |
OK, those should not be a problem, if there are not too many of them
|
Mark M. |
at any rate, it is very difficult for me to help with this sort of question in these chats
|
Pedro T. |
there are 8 of those buttons and if we include the selector they are 16
|
Pedro T. |
the first screen is ok
|
Pedro T. |
the problem is that after 2 random screens it crashes
|
Pedro T. |
each drawable is being stored on the heap
|
Pedro T. |
but you're right
|
Mark M. |
all I can tell you is that if you are convinced,
from MAT, that your problem is with your resources, you need
fewer/smaller resources
|
Pedro T. |
I will have to manage the dashboard from code
|
Pedro T. |
that is the main problem
|
Mark M. |
let me swing back to Gabriele, and I will come back to you in a bit
|
Mark M. |
Gabriele: do you have another question?
|
Pedro T. |
ok
|
Gabriele |
Another thing is when to use static objects in my
classes. For example, I've declared my webView static, but I'm not sure
which question I should answer, to know if it should be static or not. I
thought: "I should not create another instance of webview, so I can
declare it static". Is this assumption wrong? I know from Java that I
should use static when the object belongs to the Class and not to the
Object, but I can't think an example of this in android, because what
the PagerAdapter represents? Does the webview belongs to the class or to
the object? Can I have problems using static, due to android life
cycle?
|
Mark M. |
you should never declare widgets to be static
|
Gabriele |
ah, why?
|
Mark M. |
"Is this assumption wrong?" -- yes, because you are most certainly creating more than one WebView
|
Mark M. |
you have more than one page in the ViewPager, and each page is a WebView
|
Oct 9 | 8:00 PM |
Mark M. |
hence, you have more than one WebView
|
Oct 9 | 8:00 PM |
Mark M. |
oh, no, wait
|
Gabriele |
Hm. What do you mean more then one? If I create only one, in one page?
|
Mark M. |
I see, you only have two pages
|
Mark M. |
one WebView and one something else (for bookmarks)
|
Gabriele |
It's a listview, the other.
|
Mark M. |
"Does the webview belongs to the class or to the object?" -- the object
|
Mark M. |
"Can I have problems using static, due to android life cycle?" -- absolutely
|
Mark M. |
you are creating a memory leak, unless you arrange to null out that static reference somtime
|
Mark M. |
er, sometime
|
Mark M. |
your objective should be a project with zero static data members
|
Mark M. |
static data members typically are a necessity, particularly in Android development
|
Mark M. |
but the ideal Java project has no static data members at all
|
Gabriele |
Last thing, to understand better: which is an example of static data member necessity in Android?
|
Mark M. |
let's say that you are creating a camera app with a built-in image editor
|
Mark M. |
you have one activity for the camera, another activity for the editor
|
Mark M. |
when the camera activity takes a picture, while
the picture needs to be stored on disk, it will also be needed in memory
for the editor
|
Mark M. |
and a bitmap of that size is too big to pass in an Intent extra between the activiteis
|
Mark M. |
er, activities
|
Mark M. |
your options are:
|
Mark M. |
1. have the image editor read the photo back off of storage, which is slow
|
Mark M. |
2. cache the photo in a static data member, so both activities have access to it
|
Mark M. |
static data members, in Android, should
principally be used for things that need to be accessed by multiple
components (e.g., multiple activities), and then typically as an
in-memory cache for some persistent backing store
|
Gabriele |
Ah, so in this case, I'm using one-image-in-memory, to serve two and after I null the object?
|
Oct 9 | 8:05 PM |
Mark M. |
yes, eventually, the image editor activity would
want to set the static data member to null, to allow the Bitmap to get
garbage-collected
|
Gabriele |
Ok, thank you.
|
Mark M. |
Pedro: do you have another question?
|
Gabriele |
See you the next time, bye all. Thank you Mark.
|
Gabriele | has left the room |
Oct 9 | 8:10 PM |
Pedro T. |
no thanks
|
Mark M. |
OK
|
Mark M. |
if you come up with one in the remaining time, be sure to ask
|
Oct 9 | 8:30 PM |
Mark M. |
that is the end of today's chat
|
Mark M. |
the next one is Thursday at 10am Eastern
|
Mark M. |
have a pleasant day!
|
Pedro T. | has left the room |
Mark M. | turned off guest access |