Jul 23 | 8:50 AM |
Mark M. | has entered the room |
Mark M. | turned on guest access |
Jul 23 | 9:10 AM |
ndrocchietto_ivano | has entered the room |
Mark M. |
hello, Ivano!
|
Mark M. |
how can I help you today?
|
ndrocchietto_ivano |
good morning
|
ndrocchietto_ivano |
one sec loading brain...
|
Jul 23 | 9:15 AM |
ndrocchietto_ivano |
yes. i have a MainActivity and I have a Fragment attached. As I query the db by means of some Loaders, I have the need to reload the fragment to refresh the view. I reload the fragment both under the fragment itself both from a different Dialog Fragment.
|
ndrocchietto_ivano |
View paste
|
ndrocchietto_ivano |
(sorry is not formatted well)
|
ndrocchietto_ivano |
but I found much more pratical to launch an explicit intent that loads from scratch the main activity. In this way baing loaded the main activity the attached fragment is automatically called in onCreate and onCreateView and i obtain the result I want.
|
ndrocchietto_ivano |
my question is:
|
ndrocchietto_ivano |
it is this an efficient way to proceed or I mess up a bit the memory stacking activity over activity continuously, while instead working directly one fragment per time would be more indicated? I follow the launch MainActivity.class explicit intent the better way to proceed (STOP)
|
Mark M. |
let's back up a few steps
|
Jul 23 | 9:20 AM |
Mark M. |
why do you feel that you need to reload the fragment to refresh the view?
|
Mark M. |
(let alone reload the *activity* to refresh the view)
|
ndrocchietto_ivano |
because i have a list view attached to the fragment with Adapter and loaders, and need to refresh for instance because I need to launch a new query as instead of SELECT *, SELECT column WHERE, for instance.
|
Mark M. |
why not just something like restartLoader()?
|
ndrocchietto_ivano |
did not know about that
|
Mark M. |
I haven't used it, but it's on LoaderManager, and it should allow you to basically force the loader to load again
|
Mark M. |
another alternative would be to destroyLoader() the old one and initLoader() a new one, perhaps with a fresh ID
|
ndrocchietto_ivano |
that is great but i have 6 different LoadInit numbers
|
Mark M. |
so?
|
ndrocchietto_ivano |
well I am thinking that loading a loader again could be detrimental if I do not detach before the fragment, obtaining a new list view on top of the old list view
|
Mark M. |
:: shrug ::
|
ndrocchietto_ivano |
that is why i resolve the problem calling a new main activity
|
ndrocchietto_ivano |
:)
|
Mark M. |
I do not know why it would be detrimental
|
Mark M. |
if anything, I would expect it to be better
|
Mark M. |
it certainly will be faster and less memory-intensive
|
Mark M. |
and since you'
|
Mark M. |
and since you are not destroying and recreating the widgets, it might be easier to keep the user's context (e.g., scroll position in a list)
|
Jul 23 | 9:25 AM |
ndrocchietto_ivano |
true
|
ndrocchietto_ivano |
I catch this on restoresavedinstance anyway
|
Mark M. |
to draw an analogy, what you are doing is like a Web page causing itself to reload from the Web server as a way of updating it, instead of using AJAX and updating the DOM
|
Mark M. |
this works, and in the 1990's, it was pretty much our only option
|
ndrocchietto_ivano |
ah ah
|
ndrocchietto_ivano |
great example indeed
|
ndrocchietto_ivano |
it works this is for sure:)
|
ndrocchietto_ivano |
well Mark, I wish you a nice week off, and thank you very much.
|
Mark M. |
you're welcome!
|
Jul 23 | 10:00 AM |
Mark M. |
that's a wrap for today's chat
|
Mark M. |
the transcript will be posted to https://commonsware.com/office-hours/ shortly
|
Mark M. |
the next chat is Thursday at 9am US Eastern
|
Mark M. |
have a pleasant day!
|
ndrocchietto_ivano | has left the room |
Mark M. | turned off guest access |