Apr 14 | 3:50 PM |
Mark M. | has entered the room |
Apr 14 | 3:55 PM |
Mark M. | turned on guest access |
IpiRon | has entered the room |
Apr 14 | 4:00 PM |
IpiRon |
Hello!
|
Mark M. |
hello, IpiRon!
|
Mark M. |
how can I help you today?
|
IpiRon |
View paste
(34 more lines)
|
Mark M. |
um, hold on a moment while I read all of that... :-)
|
Mark M. |
"Are you aware of any detailed case studies that could server as a roadmap for implementation?" -- no
|
Mark M. |
"In the OnPowerReceiver what is the correct way to obtain the Application object" -- call getApplication() on the Context that is passed into onReceive()
|
Andrew O. | has entered the room |
Andrew O. |
Hi, I've been having trouble saving my scroll position in a listview for rotations. A friend told me that this may be because I'm constantly resetting my ListAdapter, though I haven't found information to back that up. I'm using a CursorAdapter to back my ListView and because SQL queries take some time, I get my cursor using an AsyncTaskLoader and set my adapter for my ListView in onLoadFinished() of the fragment that holds the ListView. Is my friend right? If so, what are some best practices to retain the same adapter across rotations and swap out underlying data?
|
Mark M. |
"3. Is the OnPowerReceiver the proper mechanism for determining the locking/unlocking of the screen or is there a better way to implement, say KeyGuard?" -- I have no idea
|
Mark M. |
IpiRon: I'll swing back to you in a bit to take any follow-on questions, and I apologize for not being more useful on those
|
Apr 14 | 4:05 PM |
IpiRon |
Okay
|
Apr 14 | 4:05 PM |
Mark M. |
"Is my friend right?" -- you should be creating a new adapter on a configuration change, when your activity is destroyed and recreated
|
Mark M. |
"what are some best practices to retain the same adapter across rotations" -- you don't
|
Mark M. |
hold on a moment while I research a better solution
|
Mark M. |
ah, there it is
|
Mark M. |
setSelectionFromTop()
|
Mark M. |
now, AFAIK, that's normally applied automatically
|
Mark M. |
so I don't know quite why you are encountering a problem
|
Mark M. |
but, push come to proverbial shove, hold onto the old position in the Bundle in onSaveInstanceState() (getFirstVisiblePosition()), then re-apply it yourself in after your data is ready
|
Apr 14 | 4:10 PM |
Mark M. |
your data should be coming to you immediately, assuming your AsyncTaskLoader is working properly, as the prior results will be retained across the configuration change
|
Mark M. |
if you are finding that you are re-querying the database after the configuration change, that may be your problem
|
Mark M. |
let me swing back to IpiRon, and I'll be back with you in a bit
|
Mark M. |
IpiRon: your turn -- do you have another question?
|
IpiRon |
I tried: myApp = (IntelliMessageApplication) context.getApplication(); but it says to use .getApplicationContext() so I'll live with that!
|
Mark M. |
what is "it"?
|
IpiRon |
View paste
|
IpiRon |
It was hovering over the error in Eclipse!
|
Mark M. |
OK
|
IpiRon | has left the room |
Mark M. |
oh, right, getApplication() is only on Activity
|
Mark M. |
and, um, never mind :-)
|
Mark M. |
Andrew: do you have another question?
|
Andrew O. |
It turns out I'm requerying my database on configuration changes. Is there any way to prevent this from happening?
|
Mark M. |
there's a bug in your AsyncTaskLoader somewhere, or in how you are calling initLoader()
|
Mark M. |
does your implementation of AsyncTaskLoader override any methods other than loadInBackground()?
|
Apr 14 | 4:15 PM |
Andrew O. |
Yes, onCanceled(), deliverResult(), onStartLoading(), onStopLoading(), onReset(). I call initLoader in onCreate of my fragment.
|
Mark M. |
hmmm... what are you doing in deliverResult()?
|
Andrew O. |
View paste
|
Andrew O. |
Because I didn't set retainInstance() to true, would my fragment get recreated, causing another call to initLoader?
|
Mark M. |
yes, but that's supposed to be handled by the loader framework
|
Mark M. |
effectively, your Cursor you are returning should be retained automatically
|
Mark M. |
and your next initLoader() call should arrange to deliver that same Cursor back to you
|
Andrew O. |
And onLoadFinished() wouldn't be called again?
|
Mark M. |
that I don't remember
|
Apr 14 | 4:20 PM |
Mark M. |
I gave up on the loader framework a while back
|
Apr 14 | 4:20 PM |
Mark M. |
blogged about that here: http://commonsware.com/blog/2014/03/31/cwac-loa...
|
Mark M. |
if you have another question, go right ahead
|
Apr 14 | 4:25 PM |
Andrew O. |
I'm making music player and the now playing screen has a seekbar and a couple of textviews among other things. The textviews indicate the artist/album and the title of the song. The seekbar is constantly updated by a background thread and the textviews are set to autoscroll with the marqueeForever attribute. The TextViews stop scrolling when the music is playing and the seekbar is automatically moving, and resume when the music is paused or the seekbar stops moving. I know the textview autoscroll feature has something to do with View/Widget selection, but I'm not exactly sure how to go about fixing it.
|
Mark M. |
well, the marquee effect is only supposed to take effect when the widget is selected
|
Mark M. |
which means as soon as the user touches just about anything else, the effect will stop
|
Mark M. |
if your objective is for the effect to continue regardless of user input, you're probably going to have to find some other solution
|
Andrew O. |
Oh okay, thanks. One more question: Is it possible to reorder the results in a cursor? I want to display things in alphabetical order but A-Z is before a-z. In short, I'd like to have case insensitive alphabetical order.
|
Mark M. |
ideally, you query the database that way
|
Apr 14 | 4:30 PM |
Mark M. |
I seem to recall that there's a case-insensitive option with ORDER BY
|
Andrew O. |
Okay, thanks! That's all I have for today.
|
Mark M. |
yes, COLLATE NOCASE
|
Mark M. |
e.g., ORDER BY TITLE COLLATE NOCASE
|
Andrew O. |
Thanks :)
|
Andrew O. | has left the room |
Apr 14 | 5:00 PM |
Mark M. | turned off guest access |