Oct 3 | 3:55 PM |
Mark M. | has entered the room |
Mark M. | turned on guest access |
Jeffrey | has entered the room |
Mark M. |
hello, Jeffrey!
|
Mark M. |
how can I help you today?
|
Jeffrey |
Hi Mark
|
Jeffrey |
I upload a picture
|
Jeffrey | |
Jeffrey |
View paste
|
Mark M. |
um, that's probably not going to be the fragment's job
|
Mark M. |
off the cuff, I would have your ViewHolder deal with the changes
|
Mark M. |
is this for all the rows in the RecyclerView? meaning if there are 10 rows visible, all 10 are flipping at once?
|
Jeffrey |
yes
|
Jeffrey |
I want to re layout 10 rows for every 30 seconds
|
Mark M. |
use postDelayed() to get control every 30 seconds while you are in the foreground, probably at the fragment level
|
Mark M. |
have the fragment iterate over the ViewHolders and tell each to flip(), where you implement flip() to do your layout change
|
Oct 3 | 4:00 PM |
Mark M. |
at least, that's the approach I would start with
|
Jeffrey |
ok thanks
|
Jeffrey |
I have another idea but I do not know how to do it
|
Jeffrey |
View paste
|
EGHDK | has entered the room |
Mark M. |
(BTW, hello, EGHDK -- I will be with you shortly!)
|
Mark M. |
Jeffrey: you would do the same thing that I just described, except flip() would change the visibility of widgets
|
Mark M. |
though your approach is going to be more expensive in terms of heap space (twice the number of widgets)
|
Mark M. |
and you'll need to remember to update the soon-to-be-visible widgets to have the same contents as the soon-to-be-gone widgets when you flip
|
Mark M. |
let me take a question from EGHDK, and I will be back with you shortly
|
EGHDK |
hey mark, ill just post my question(s) and you can get to them when you get to them. i'm working a lot on rotation and making sure that the state of my activity is there on config change. few questions about it. 1. If my process is killed will I get a bundle back? I'm asking because i set the dev option for process to none, and I save stuff onSaveInstanceState but I'm not getting anything back when I open it back up. 2. I thought if I had 20 activities in my app stack, 1 through 19 could get destroyed, if I'm looking at 20, I know you responded to a SO question about this. and apparently android won't kill an activity it will kill a process, but I've noticed that thats not true. some low end phones are killing activities in my task stack, and now i have to recreate them properly. http://stackoverflow.com/questions/7536988/andr...
|
Mark M. |
EGHDK: your turn! do you have a question?
|
Jeffrey |
ok thanks
|
Jeffrey |
Hi EGHDK
|
Bryan | has entered the room |
Mark M. |
"1. If my process is killed will I get a bundle back?" -- um, that depends on circumstances (e.g., is your task still considered outstanding)
|
Mark M. |
"and apparently android won't kill an activity it will kill a process, but I've noticed that thats not true" -- yes, it is
|
EGHDK |
outstanding?
|
Mark M. |
active, whatever
|
Mark M. |
I don't know the precise adjective
|
EGHDK |
Okay, well, lets go with first question.
|
Mark M. |
roughly speaking, it's about 30 minutes from when the user was last in the task
|
Oct 3 | 4:05 PM |
Mark M. |
(BTW, hello, Bryan -- I will be with you shortly)
|
Bryan |
sounds good
|
EGHDK |
I turn the dev option to have no processes running, so in my activity I saveinstancestate() and I go home, I open the app again, and no bundle =(
|
Mark M. |
EGHDK: beats me. I focus on the real world, more so than semi-random developer option settings.
|
Mark M. |
I have never used that particular option and I have no idea what its effects are with respect to tasks
|
Mark M. |
if you want to terminate your process, do so from your IDE
|
EGHDK |
Okay, so let me get this straight though, if I was telling someone about processes in android, a process can die, and if you go back into your app, you "should" get a bundle back?
|
Mark M. |
if you go fairly quickly back into your app, your activity that is on top of the back stack of the task should get its saved instance state Bundle
|
Mark M. |
where by "fairly quickly", I mean within 30 minutes or so
|
EGHDK |
Mark, Okay I'll try the option from the ide... I better get my bundle back!
|
Mark M. |
let me take questions from the others, and I'll be back with you shortly
|
Mark M. |
Bryan: your turn! do you have a question?
|
Bryan |
I have an app that starts a persistent notification
|
EGHDK |
and yes, I'm trying fairly quickly because I'm trying to test if my Boolean progressDialogShouldAppear in my bundle.
|
Bryan |
and that can stay open even if the user "closes" the app through the recent tasks
|
Bryan |
I am trying to implement a "close all services and processes and everything having to do with this app" button
|
Oct 3 | 4:10 PM |
Bryan |
but due to some stray something or other, even after I kill it all after toggling airplane mode it pops up the notfication
|
Bryan |
so my question is: is there a way to hunt down what exactly is starting my application again?
|
Mark M. |
under what circumstances do you show the notification?
|
Bryan |
I have a class that extends Application that has all the services and listeners coming off of it
|
Bryan |
it shows on app startup
|
Mark M. |
what does "app startup" mean, exactly?
|
Bryan |
well, originally it was when the user starts the app or boot_completed got fired
|
Bryan |
but it seems to have a mind of its own now
|
Bryan |
and starts "on it's own"
|
Bryan |
I have traced it back to the extedended Application starting back up
|
Bryan |
but I don't know how to trace backwards from that to see what is causing it to open
|
Mark M. |
ok, so your Application is causing the Notification to appear
|
Bryan |
(in this test case, after toggling airplane mode)
|
Bryan |
yes
|
Bryan |
I can stop that on the "down" from Application, but I want to know what is causing the Application to start back up
|
Mark M. |
with respect to your "close all services..." button, how *exactly* are you doing that?
|
Bryan |
sure, one sec
|
Mark M. |
(in terms of the work being done, not putting the action on the Notification, that is)
|
Bryan |
right, I stop some listeners, close the notification and then do "stopSelf()" on my 2 running services and then do a finishAndRemoveTask() on my only activity
|
Mark M. |
hmmmm...
|
Bryan |
there might be a stray listener/receiver that I haven't stoppped
|
Bryan |
that gets an event that gets fired on toggle airplane mode
|
Oct 3 | 4:15 PM |
Mark M. |
there's no great way from Application onCreate() to determine why Application onCreate() is being called
|
Bryan |
ok
|
Mark M. |
other than to examine LogCat at that point in time and see if you see anything interesting
|
Bryan |
makes sense, I was hoping for something automagical
|
Mark M. |
my gut reaction was that Android was restarting your service, but stopSelf() should be preventing that
|
Bryan |
but looks like I will have to do some work
|
Bryan |
does a receiver start a new instance of Application if there isn't one?
|
Bryan |
receiver/listener/etc
|
Mark M. |
yes
|
Mark M. |
well, not listeners, insofar as the process must already exist by that point
|
Mark M. |
Application, and any ContentProviders, are created first thing when your process starts up
|
Bryan |
so if the Application closes how does a listener or service even exist?
|
EGHDK |
Bryan, any app components would need your app class to start. So by your App class starting, it means some other component was told to start
|
Mark M. |
the Application never "closes" -- it lives until the process terminates
|
Mark M. |
if the process is gone, all your Java objects are gone
|
Bryan |
that is what happens
|
Bryan |
according to the App->running in settings
|
Bryan |
there is nothing there for my app
|
Mark M. |
I wouldn't trust that
|
Bryan |
but then, poof, it starts, shows the persistant notification and then goes away again
|
Bryan |
DDMS shows the same
|
Mark M. |
that's better
|
Bryan |
or rather, doesn't show my app
|
Mark M. |
besides, if onCreate() is what is triggering the notification, you know that you are getting your new process
|
Bryan |
ok, that lets me know where I need to go next
|
Bryan |
Thanks!!
|
Mark M. |
that will be caused by something starting your activity, starting or binding to a service, or sending a broadcast to a manifest-registered receiver
|
Mark M. |
hopefully, there's a reasonably finite list of those things :-)
|
Mark M. |
if not, see if they'll lay in a Red Bull pipeline right to your desk
|
Mark M. |
let me take questions from the others, and I'll be back with you in a bit
|
Mark M. |
Jeffrey: your turn! do you have another question?
|
Bryan |
thanks, have a good one
|
Oct 3 | 4:20 PM |
Jeffrey |
ok thanks
|
Jeffrey |
How to use postDelayed() -- Handler? use a Handler in the ViewHolder to implement postDelayed() ?
|
Mark M. |
postDelayed() is also implemented on View
|
Mark M. |
so, you could call it on the RecyclerView
|
Mark M. |
I wouldn't bother creating a Handler just to use postDelayed()
|
Jeffrey |
ok, How to make frament iterate over the ViewHolders and tell each to flip() ?
|
Mark M. |
count from 0 to size-1, and call findViewHolderForLayoutPosition() for each
|
Mark M. |
checking for null responses, meaning there is no ViewHolder for that position at the moment
|
Jeffrey |
do you have any example in your book that I can get an example?
|
Mark M. |
of postDelayed(), yes
|
Mark M. | |
Mark M. |
of iterating over the ViewHolders, no
|
Jeffrey |
ok thanks a lot.
|
Mark M. |
let me take questions from the others, and I'll be back with you shortly
|
Mark M. |
EGHDK: your turn! do you have another question?
|
EGHDK |
Back to my ques number 2. I thought if I had 20 activities in my app stack, 1 through 19 could get destroyed, if I'm looking at 20, I know you responded to a SO question about this. and apparently android won't kill an activity it will kill a process, but I've noticed that thats not true. some low end phones are killing activities in my task stack, and now i have to recreate them properly.
|
Oct 3 | 4:25 PM |
Mark M. |
you are welcome to publish a sample app that demonstrates your behavior
|
Mark M. |
my guess is that you are misinterpreting some symptoms
|
EGHDK |
I guess... maybe, but at the same time... everything in the docs makes it look like it is possible.
|
Mark M. |
you already linked to the Android engineer who disputes the docs
|
Mark M. |
and the docs have many bugs
|
EGHDK |
I just think hackbod is wrong in her answer. maybe not wrong, but just... idk. Why would the docs be wrong for so long.
|
EGHDK |
I guess, but ugh. its fruterating.
|
Mark M. |
welcome to my world
|
EGHDK |
So if I was telling someone about activites, would it be proper to say "if your process is open none of your activities will be destroyed by the system"?
|
Mark M. |
they'll be destroyed if something destroys them (i.e., calls finish())
|
Mark M. |
they won't be destroyed due to low memory conditions, for the simple reason that it won't really help
|
EGHDK |
why wont it really help?
|
EGHDK |
makes sense to me that it could help
|
Mark M. |
it will free up *heap space*
|
Jeffrey | has left the room |
Mark M. |
"low memory conditions" refers to *system RAM*
|
Mark M. |
and while it is possible that freeing up heap space might return some memory pages to the OS, it's rather unlikely on Android 4.4 and below, due to the nature of Dalvik's garbage collection implementation
|
Oct 3 | 4:30 PM |
Bryan | has left the room |
EGHDK |
gotcha. so basically when your app starts, it takes from the system ram a certain amount, whether you like it or not?
|
Mark M. |
it grabs incrementally, starting with a chunk and allocating more system RAM as needed
|
Mark M. |
however, it does so in "pages" (8K or thereabouts)
|
Mark M. |
and it can only release a page back to the OS if the page is completely empty
|
Mark M. |
garbage collection *can* cause a page to become empty, but for many pages, there's still some live objects floating around that are using those pages
|
Mark M. |
and so even if the page is 99% empty, the page cannot be released back to the OS
|
EGHDK |
got it
|
Mark M. |
now, things are a bit better with ART on Android 5.0+, at least if your app spends some time in the background
|
Mark M. |
in that it's a bit more likely that pages can be freed and returned to the OS
|
Mark M. |
but that's not going to change Android's approach to dealing with activities, which is they're alive until somebody finish()-es them
|
EGHDK |
okay. so I'm going to go back to my app and see why the heck I'm getting an issue, but I still think it's happening because the activity doesn't look the same when I come back to it of when I left it. and the only way to duplicate this behavior is by using the dev option of "Do not keep activities".
|
Mark M. |
just as services are running until somebody calls stopService(), stopSelf(), unbindService(), etc.
|
EGHDK |
Mark, a service can be stopped by the system and restarted if sticky.. right?
|
Mark M. |
no
|
Mark M. |
if the process is terminated (despite the service), the sticky behavior means Android will start a fresh process and start up the service again sometime soonish
|
Oct 3 | 4:35 PM |
Mark M. |
but Android won't stop services on its own (short of terminating the whole process), just as it won't destroy activities on its own (short of terminating the whole process)
|
EGHDK |
okay, that was a little bit of a tanget, but good to know. but back to the activities, why does the activity limit dev option even exist then if that's basically guaranteed not to happen?
|
Mark M. |
mostly, its there to force developers to test configuration changes
|
Mark M. |
basically, it destroys the activity when you leave it, and re-creates it if you return to it (e.g., pressed BACK on the activity that you started from it)
|
Mark M. |
this destroy-and-recreate is also the behavior on a configuration change
|
Mark M. |
having the "do not keep activities" checkbox checked basically means you're testing your saved instance state logic all the time
|
Mark M. |
just by navigating forwards and backwards within your app
|
Mark M. |
rather than having to remember to rotate the screen or something
|
EGHDK |
yeah, so I guess if my configuration change works fine then I shouldn't have to worry about why my activity "seemingly" gets killed in this scenario.
|
Oct 3 | 4:40 PM |
EGHDK |
so Ive got some things to test. ON to some other random questions I have marked down. 1. unused resources like images, I know theres a flag to enable in build.gradle but it requires proguard... do you know of another way to do this? enabling proguard is causing me issues.
|
Mark M. |
to do what?
|
EGHDK |
sorry, flag to enable to remove unused resources
|
Mark M. |
I think a manual Lint run (Analyze > Analyze Code in Android Studio) will report unused resources
|
Mark M. |
but you'll have to clean them up manually
|
Oct 3 | 4:45 PM |
EGHDK |
okay, worth a try. Wondeirng if maybe theres just a way to turn on proguard without it really running on any of my fiels.
|
Mark M. |
in that case, it won't know what resources are unused
|
EGHDK |
yeah, I guess that makes sense
|
EGHDK |
Any experience with checkstyle and how to enable it and such?
|
Mark M. |
haven't used it, though I know there's a Gradle plugin for it
|
Oct 3 | 4:50 PM |
EGHDK |
I have a progressdialog showing, and I save instanceState basically saying Boolean shouldShowProgress and on rotation I just create a new progress dialog. It works and all... but I get a window leaked. ideas?
|
Mark M. |
use a DialogFragment
|
Mark M. |
and get rid of the boolean
|
Mark M. |
DialogFragment will automatically redisplay the dialog after a configuration change, if the dialog was displayed at the time of the configuration change
|
EGHDK |
Okay, so if I ever need to show a popup window ish thing in my app I should be using a dialogfragment?
|
Mark M. |
if you ever need to show a Dialog in your app, you should be using a DialogFragment
|
Mark M. |
there are lots of other "popup window ish things" that are not subclasses of Dialog (e.g., PopupWindow)
|
EGHDK |
I'm guessing in most cases I'll just want to use a DialogFragment. I guess I'll never use a PopupWindow because I've never even heard of it before. lol
|
Oct 3 | 4:55 PM |
EGHDK |
So a lot of apps lately ship with a way to change themes at runtime just about, and it changes the Actionbar and widget colors, whats the best way to do this in my app?
|
Mark M. |
off the top of my head, I have no idea
|
Mark M. |
actually, with appcompat-v7, you should be able to change tints on the fly
|
Mark M. |
as that's what Palette does, deducing a color scheme from an image and allowing you to change your look to match
|
Mark M. |
beyond that, I'd look for some libraries to see if somebody has a reusable dynamic theme engine or something
|
EGHDK |
okay, does tinting basically work on every widget now on every api level 15 and up? I thought tint was only new to lollipop
|
Mark M. |
appcompat-v7 provides tinting for a subset of widgets, plus its action bar backport, going back to API Level 7
|
Mark M. |
I don't recall off the top of my head the exact roster of affected widgets, but it's fairly extensive in the latest appcompat-v7 releaes
|
Mark M. |
er, release
|
Oct 3 | 5:00 PM |
Mark M. |
note, though, that you get the whole material look, not just the tinting (e.g., action bar with no icon, all-caps button captions)
|
Oct 3 | 5:00 PM |
EGHDK |
okay. that's all for today. thanks mark
|
Oct 3 | 5:00 PM |
Mark M. |
yup, that's a wrap for the chat
|
Mark M. |
next one is Monday at 7:30pm US Eastern
|
Mark M. |
have a pleasant day!
|
EGHDK | has left the room |
Mark M. | turned off guest access |