Jul 22 | 7:25 PM |
Mark M. | has entered the room |
Mark M. | turned on guest access |
Jul 22 | 7:30 PM |
Jeff G. | has entered the room |
Mark M. |
hello, Jeff!
|
Mark M. |
how can I help you today?
|
Jeff G. |
Hi!
|
Jeff G. |
regarding loaders. your opinion on "oncontentchanged vs restartloader"
|
Mark M. |
my opinion on loaders is "just say no"
|
Jeff G. |
lol.
|
Mark M. | |
Jeff G. |
alternatives?
|
Jul 22 | 7:35 PM |
Mark M. |
event bus, AsyncTask, etc.
|
Jeff G. |
okay, I'll have to look into that.
|
Mark M. |
the only problem that CursorLoader solves that I think is a worthwhile problem is the reload-the-Cursor-when-the-data-changes feature
|
Mark M. |
and that can be handled by other means, ranging from your own ContentObserver (if you're using a ContentProvider for other reasons) or a general-purpose event bus
|
Jeff G. |
I'm using AsyncTaskLoader
|
Mark M. |
I think AsyncTaskLoader is abstract
|
Jeff G. |
I use ormlite to query a local sqlite database.
|
Mark M. |
so you have an OrmLiteLoader or something that extends AsyncTaskLoader
|
Mark M. |
that sounds like the SharedPreferencesLoader and SQLiteCursorLoader that I implemented and eventually dropped, as they were impractical
|
Jeff G. |
I have a loader that extends AsycnTaskLoader.
|
Jul 22 | 7:40 PM |
Jeff G. |
I will definitely look into alternatives, but I am working within a framework that is heavily dependent upon loaders developed by other people. So, given that constraint, when is oncontentchanged used and when is restartloader used?
|
Mark M. |
beats me
|
Mark M. |
or, more accurately, I forget
|
Mark M. |
you're referring to your AsyncTaskLoader implementation, right?
|
Jeff G. |
yes.
|
Jeff G. |
I just want to know the proper way to allow for the loader to reload itself when data changes.
|
Mark M. |
give me a moment to review my implementations -- hold on
|
Jeff G. |
thanks.
|
Mark M. |
OK, I'm back to "beats me"
|
Jeff G. |
okay, perhaps another question then on a different topic?
|
Mark M. |
it's at least worth a try :-)
|
Mark M. |
(I was only using forceLoad(), not dealing with either of your requested methods)
|
Jeff G. |
i've got an app with lint messages complaining about using getSupportActionBar instead of getActionBar.
|
Jeff G. |
however, if I replace them then getActionBar is underlined in red as not being defined.
|
EGHDK | has entered the room |
Jul 22 | 7:45 PM |
Mark M. |
off the cuff, sounds like a Lint bug
|
Jeff G. |
Ok.
|
Jeff G. |
my app only targets the nexus 7
|
Jeff G. |
so perhaps I can just get rid of the app compat stuff?
|
Mark M. |
absolutely
|
Jeff G. |
any gotchas to worry about when doing so?
|
Mark M. |
there's no good reason to use AppCompat with a minSdkVersion 11 or higher
|
Mark M. |
none that I can think of
|
Jeff G. |
I inherited this project so...
|
Mark M. |
ah
|
Jeff G. |
can you point me to a URL on how to do the upgrade or is it pretty easy?
|
Mark M. |
well, one gotcha: are you using MediaRouteActionProvider?
|
Jeff G. |
no
|
Mark M. |
(BTW, howdy, EGHDK -- be with you shortly!)
|
Mark M. |
Step #1: remove the appcompat-v7 library project reference from your project
|
Mark M. |
Step #2: fix all the compile errors that result from Step #1
|
Mark M. |
Step #3: beer
|
Mark M. |
:-)
|
Mark M. |
it's pretty straightforward
|
Jeff G. |
got it. thanks!
|
Mark M. |
you'll wind up fixing your theme, removing the app: attributes in your menu items, and no longer inheriting from ActionBarActivity
|
Jeff G. |
straightforward but tedious?
|
Mark M. |
and changing imports to their Android SDK standard ones
|
Mark M. |
tedium depends on the size of the app
|
Mark M. |
bigger apps might require doing Step #2 and Step #3 repeatedly, in a loop
|
Jeff G. |
okay but if I remove the reference will it be pretty obvious what things break?
|
Jeff G. |
i.e., the IDE complains about it?
|
Mark M. |
lotsa red
|
Mark M. |
oh yeah
|
Jeff G. |
haha. ok.
|
Jeff G. |
thanks.
|
Mark M. |
EGHDK: your turn -- do you have a question?
|
EGHDK |
Hey Mark. First issue. I have activity A, then B. I press home. In my GCM receiver I set a notification with a PendingIntent to open Activity A. I get a notification. I click the notification. I'm at A. I press back, I go to B, then back again, and I'm at A. How do I clear my entire task and only have A open?
|
Mark M. |
I used FLAG_ACTIVITY_CLEAR_TOP and FLAG_ACTIVITY_SINGLE_TOP as flags on my Intent
|
Mark M. |
that is wrapped in the PendingIntent
|
Jul 22 | 7:50 PM |
Mark M. |
that keeps it in your task, but wipes out the task
|
Mark M. |
FLAG_ACTIVITY_NEW_TASK would start a separate task
|
EGHDK |
Interesting. Because I didn't do exactly that (I did) setFlags()NEW_TASK and CLEAR_TASK
|
EGHDK |
but it didn't work.
|
Mark M. | |
Mark M. |
that's Google's official guidance on the subject
|
EGHDK |
View paste
|
EGHDK |
and it still didn't work.
|
Mark M. |
CLEAR_TOP/SINGLE_TOP worked for me the last time I tried it
|
Mark M. |
it's been a while, though, since I played with that
|
EGHDK |
Okay. I will try that. If it doesn't work. Any recomendation on debugging this?
|
EGHDK |
Because I thought for sure the answer here: http://stackoverflow.com/questions/5979171/clea...
|
Mark M. |
task information is probably in adb shell dumpsys somewhere
|
EGHDK |
would work.
|
EGHDK |
And it didn't. So I'm thinking it's because of my pendingIntent.
|
Mark M. |
possibly
|
Mark M. |
unfortunately, where I had this in the book was in a previous generation of tutorials
|
Mark M. |
and I failed to reimplement it in a regular book sample
|
Mark M. |
which I'll have to address at some point
|
EGHDK |
Alright.
|
EGHDK |
Is there anything I can do in the activity?
|
EGHDK |
To clear all the tasks behind it?
|
Mark M. |
nothing that would deal with this on a one-off basis
|
Jul 22 | 7:55 PM |
Mark M. |
which is usually what you want for this sort of scenario, rather than saying the activity *always* has the behavior
|
Mark M. |
let me swing back to Jeff for a bit, and I'll be back with you shortly
|
Mark M. |
Jeff: do you have another question?
|
EGHDK |
Yeah but I figure as a fail safe for now. I'll pass an extra, so I know that intent came from a notification, and on onCreate I'll wipe the other activites from the task.
|
Mark M. |
OK, EGHDK, back to you
|
EGHDK |
I guess I will have to look into this tomorrow. I'm not in front of my workspace right now.
|
EGHDK |
I have another question though.
|
Mark M. |
go right ahead
|
EGHDK |
I have a list view with two distinctly different row layouts.
|
Jul 22 | 8:00 PM |
EGHDK |
I've had this working for quite some time.
|
EGHDK |
I was using all of the proper adapter API to specify that I have two types of list items.
|
EGHDK |
Recently it seems like I get back the incorrect viewHolder.
|
EGHDK |
I specifically don't, but in crash reports I do.
|
Mark M. |
you're getting ClassCastExceptions?
|
EGHDK |
AViewHolder cannot be cast to BViewHolder.
|
EGHDK |
And it is MIND boggling how thats happening.
|
Mark M. |
that's tough to answer in the abstract, sans code
|
Mark M. |
how are you associating the ViewHolder with the row?
|
Mark M. |
the one-argument form of setTag()?
|
EGHDK |
Yeah.
|
Mark M. |
by the time you have retrieved the ViewHolder and are getting the ClassCastException, have you done much else with the row?
|
Mark M. |
IOW, are you sure the issue isn't that row recycling itself is somehow breaking, and you're actually getting row type B when you should be getting row type A?
|
EGHDK |
If it's null then I do the initial setting up of view holders
|
EGHDK |
I think that's whats happening. I'm getting type B when I should get type A.
|
Mark M. |
do you perhaps have an inconsistency between your getItemViewType() and getView() methods?
|
Mark M. |
where getItemViewType() might return A when getView() thinks it should be B, or vice versa?
|
Jul 22 | 8:05 PM |
EGHDK |
But I've never gotten the crash to occur, and I use it all the time.
|
EGHDK |
So I'm finding it tough to fix.
|
EGHDK |
It seemingly works perfectly most of the time.
|
Mark M. |
you could try having the Test Monkey beat on it a while, and see if it can trigger the error
|
EGHDK |
Do you think that listView could be handing me back the incorrect view holder?
|
Mark M. |
I can't rule it out, but I'd say the odds are better that the problem is in your code somewhere
|
Mark M. |
(BTW, Jeff, if you're back, let me know)
|
EGHDK |
Yeah. For now, I think I'm gonna catch the classcastexception, and then call getViewA again, with the view holder set to Null. So that it'll just regenerate as it woiuld the first time around.
|
EGHDK |
I've never had the error happen before. But now the activity handles multple adapters, and that seems to have caused it. Even if the other adapters are never set
|
EGHDK |
But overall is my pattern correct? getView() { if (typeA){getViewA} else if (typeB){ getViewB}}. And I have two separate view holders. Thats the general idea... right?
|
Jul 22 | 8:10 PM |
Jeff G. | has left the room |
Mark M. |
that's fine, so long as your if (typeA) is really based on getItemViewType()
|
Mark M. |
or uses the *exact* same algorithm as getItemViewType() uses
|
EGHDK |
Yeah. it is getItemViewType.
|
EGHDK |
WHich at first I thought was the problem, but watching that romain guy video on listView. He seemed to say that it was smart enough not to hand you back the wrong thing.
|
Mark M. |
correct
|
EGHDK |
Okay. Whats the deal with classes that have a period in the name? ie ActivityManager.RunningTasks?
|
EGHDK |
What's the name of that kind of class?
|
Mark M. |
they are public static inner classes
|
EGHDK |
InnerClass?
|
EGHDK |
Anytime I encounter them I have a problem using them.
|
EGHDK |
Using the constructor in the docs didn't do anything.
|
EGHDK |
ActivityManager.RunningTaskInfo()
|
EGHDK |
My object was null.
|
Mark M. |
you don't create instances of that class
|
EGHDK |
Just "that" class, or any public static inner classes?
|
Mark M. |
not all public static inner classes
|
Mark M. |
but probably more than just "that" class
|
EGHDK |
Is there any easy way to tell when I'm not do create an instace of a class?
|
Jul 22 | 8:15 PM |
EGHDK |
Okay. Got to run. I'll let you finish your answer and I'll pick up on this question next time. Thanks.
|
Mark M. |
in general, the easy way is to read the documentation
|
Mark M. |
in this case, the documentation lacks the pointer back to the method on ActivityManager where you get instances of this class
|
Jul 22 | 8:20 PM |
EGHDK |
Okay. So it wasn't my "fault", but if I read into ActivityManager I probably wouldn've found my answer.
|
EGHDK |
Great thanks.
|
EGHDK |
Have a good night.
|
Mark M. |
have a pleasant evening!
|
Jul 22 | 8:30 PM |
EGHDK | has left the room |
Mark M. | turned off guest access |