Jul 9 | 7:20 PM |
Mark M. | has entered the room |
Mark M. | turned on guest access |
Jul 9 | 7:25 PM |
Shawn V. | has entered the room |
Shawn V. |
Hi
|
Mark M. |
hello, Shawn!
|
Mark M. |
how can I help you today?
|
Shawn V. |
I am having an issue with using a ViewStub
|
Jul 9 | 7:30 PM |
Mark M. |
I can try to help, but I have limited experience with ViewStub
|
Shawn V. |
I tried to read about it in the latest book, but I couldn't find a section describing it
|
Mark M. |
did I mention that I have limited experience with ViewStub? :-)
|
Shawn V. |
Lol
|
Shawn V. |
So do I
|
Mark M. |
so... what is your issue?
|
Shawn V. |
I can replace with ViewStub with a LinearLayout and to the happy, removeAllViews, getLoutInflater, addView thing
|
Shawn V. |
And that works
|
Shawn V. |
But I am trying to learn how to do it the right way
|
Shawn V. |
So my problem with the ViewStub is that after onResume of a Fragment, the ViewStub seems to lose it viewParent
|
Shawn V. |
And that makes things... well sad, inflates fail (because no viewParent)
|
Mark M. |
do you mean, after a configuration change, like a screen rotation?
|
Shawn V. |
Nope
|
Shawn V. |
Switch to different app and come back
|
Shawn V. |
I have the screen rotation happily taken care of
|
Mark M. |
do you know if your process is being terminated between when you leave the app and come back to it?
|
Shawn V. |
Process is not being terminated
|
Shawn V. |
So no onCreateView() being called, etc... just onResume when I come back
|
Jul 9 | 7:35 PM |
Mark M. |
OK, give me a moment to do a bit of research
|
Shawn V. |
Sure, I've been fighting it all day in various ways.
|
Shawn V. |
Thanks
|
Mark M. |
just to confirm, you
|
Mark M. |
er, let's try that again...
|
Mark M. |
just to confirm, you are setting up a fragment that, in whatever it is returning from onCreateView(), has a ViewStub
|
Mark M. |
you are not inflating the ViewSTub
|
Mark M. |
you are switching to another app (e.g., recent-tasks list)
|
Mark M. |
you are returning to your app
|
Mark M. |
you are then trying to inflate the ViewStub
|
Mark M. |
and then you go BOOM due to the missing parent
|
Shawn V. |
A little different but not much
|
Mark M. |
do I have that right?
|
Shawn V. |
Setting up a OnCreateView() which has a layout that contains a ViewStub
|
Shawn V. |
In onResume, based on a state, I am inflating the ViewStub
|
Shawn V. |
I am switching to another app
|
Shawn V. |
I am returning to the app
|
Shawn V. |
Then I am trying to inflate the view stub again (since onResume is being called)
|
Mark M. |
why are you trying to inflate the ViewStub again?
|
Shawn V. |
And Boom, due to missing mParent
|
Mark M. |
or, are you saying you didn't inflate it the first time, and now the state has changed and you're trying to inflate it?
|
Shawn V. |
I did inflate it the first time, but the state has changes and I need to inflate it again (differently)
|
Mark M. |
I think that's your problem right there
|
Mark M. |
AFAIK, you can't inflate it again
|
Jul 9 | 7:40 PM |
Mark M. |
a ViewStub is a one-time deal
|
Mark M. |
"When a ViewStub is made visible, or when inflate() is invoked, the layout resource is inflated. The ViewStub then replaces itself in its parent with the inflated View or Views. Therefore, the ViewStub exists in the view hierarchy until setVisibility(int) or inflate() is invoked."
|
Mark M. |
hence, I would expect there to be a null parent after an inflate()
|
Shawn V. |
Ok I understand, but I don't know of a work around besides only inflating in the onCreateView
|
Mark M. |
you would either need N ViewStubs (one per state) and get rid of the results of any previous inflation, or go with some other solution entirely for your circumstance
|
Shawn V. |
Or not using a viewStub
|
Mark M. |
how many states are there, for which you want different content?
|
Shawn V. |
3
|
Shawn V. |
How would I switch them after I inflate one
|
Mark M. |
well, to be honest, I'm unconvinced that ViewStub is really designed for your use case
|
Shawn V. |
Me too
|
Shawn V. |
Didn't design it unfortunately
|
Mark M. |
to get rid of the results of an inflate(), call removeView() on the parent, passing in the root of what got inflated
|
Shawn V. |
As a side note, I don't like Fox Entertainment :)_
|
Shawn V. |
Ah
|
Mark M. |
or, leave the inflated stuff there and make it GONE from a setVisibility() standpoint
|
Shawn V. |
True
|
Jul 9 | 7:45 PM |
Shawn V. |
Inflate all 3 and make them all gone, until I need one?
|
Mark M. |
there are a variety of possibilities
|
Mark M. |
if they're all fairly simple, you might just have them all in the layout, set visible or gone as appropriate for your initial state, and toggle visibility
|
Shawn V. |
Okay
|
Shawn V. |
I can give that a shot
|
Mark M. |
if they are moderately expensive, you might inflate them as needed, but then just make them GONE (and make them VISIBLE again if you need them again)
|
Mark M. |
if they are heinously expensive, you might inflate them as needed, then remove them when you do not need them
|
Mark M. |
it's the classic RAM-vs.-CPU tradeoff
|
Shawn V. |
Thanks, I understand
|
Mark M. |
in terms of inflating them, either have three ViewStubs, or just use LayoutInflater directly and skip the ViewStub
|
Jul 9 | 7:50 PM |
Mark M. |
BTW, if you have another question, go right ahead -- it's a quiet chat room tonight
|
Shawn V. |
Thanks :)
|
Jul 9 | 8:00 PM |
Shawn V. |
Organization of jniLibs, native library directories
|
Mark M. |
Oooo! Am I on "Jeopardy!" ?
|
Shawn V. |
If you have several SDKs included in an application and many of them contain different processor folders
|
Mark M. |
"What is... stuff that I don't do much with either?"
|
Shawn V. |
Sorry
|
Mark M. |
:-)
|
Mark M. |
go ahead
|
Shawn V. |
Basically, I have a ton of video players in the app I work on.
|
Shawn V. |
I have been putting all the jniLibs, native files in the main project
|
Shawn V. |
Under their different processors
|
Shawn V. |
However, now that I have so many
|
Shawn V. |
The fallback logic for some specific ones is messed up
|
Shawn V. |
I was wondering if I made a separate project for each SDK
|
Shawn V. |
So that the jars that reference the native libs
|
Shawn V. |
were in the same project, but separated from the other SDKs
|
Shawn V. |
If that would straighten out the native library fail over logic
|
Jul 9 | 8:05 PM |
Shawn V. |
By that I mean, if you have an armeabi folder
|
Mark M. |
are they all going into one app?
|
Shawn V. |
Yep
|
Mark M. |
then I really doubt that it will make a difference
|
Shawn V. |
Yep, that is what others were saying in my group
|
Shawn V. |
I just wasn't sure how all that gets organized
|
Mark M. |
it's more that, by the time it gets to the APK, where the stuff came from (library module, app, etc.) all gets lost
|
Shawn V. |
Makes sense
|
Mark M. |
there may be code organization reasons for separation, but there should be no change in runtime behavior
|
Mark M. |
that being said, if you're shipping a "fat APK" with all the CPU architectures, have you considered switching to per-architecture APKs, using splits in Gradle?
|
Shawn V. |
I have but even doing that the jars are so big, that they dwarf the size of the native files
|
Mark M. |
ah
|
Shawn V. |
The armeabi is hugs
|
Shawn V. |
huge
|
Shawn V. |
but all of the other processor folder are somewhat small
|
Shawn V. |
but most of the processors (I think, I could be wrong) try to "emulate" the arm
|
Jul 9 | 8:10 PM |
Mark M. |
clearly, you need to convince management to standardize better on video formats... :-)
|
Shawn V. |
If they can't find the proper architecture folder. X86 will fall over to the armeabi folder if there is no x86 folder...
|
Shawn V. |
I'm an integrator
|
Mark M. |
for many x86 devices, yes, via libhoudini
|
Shawn V. |
The reason for the many different types is for the many different content providers, FOX, ABC, CBS, NBC, ESPN
|
Mark M. |
ah
|
Shawn V. |
And even some of the networks use different providers.
|
Shawn V. |
Right now, NBC is using three different formats: One for normal, One for local, and one for regional sports
|
Shawn V. |
Crazy folks, every one of them
|
Jul 9 | 8:15 PM |
Shawn V. |
Thank you for the first answer. It worked out fine. parent.removeAllViews(), parent.addView(viewStub), viewStub.setLayoutResources(), viewstub.inflate()
|
Shawn V. |
Fixes the issue.
|
Jul 9 | 8:20 PM |
Mark M. |
I'm not quite certain what using a ViewStub there dynamically buys you over just using a LayoutInflater
|
Mark M. |
that being said, if it is working, I'm glad to hear it
|
Shawn V. |
It doesn't buy my anything, but what I inflate connects to a library which handles clicks and opens a webview for ads
|
Shawn V. |
If I replace the viewStub with any type of normal layout, the ad click handler in the library doesn't work
|
Mark M. |
right, but you could inflate it via a LayoutInflater, bypassing the extra baggage of the ViewStub
|
Mark M. |
parent.removeAllViews(); inflater.inflate(R.layout.whatever, parent, true);
|
Mark M. |
anyway, just a thought
|
Shawn V. |
I will try it
|
Jul 9 | 8:30 PM |
Mark M. |
that's a wrap for today's chat
|
Mark M. |
the transcript will be posted to https://commonsware.com/office-hours/ shortly
|
Shawn V. |
Have a good night.
|
Shawn V. |
Thanks for the help.
|
Mark M. |
you are very welcome
|
Mark M. |
the next chat is Monday at 4pm US Eastern
|
Mark M. |
have a pleasant day!
|
Shawn V. |
You too.
|
Shawn V. | has left the room |
Mark M. | turned off guest access |