Jun 27 | 7:25 PM |
Mark M. | has entered the room |
Mark M. | turned on guest access |
EGHDK | has entered the room |
Mark M. |
hello, EGHDK
|
Mark M. |
how can I help you today>
|
EGHDK |
View paste
|
Mark M. |
why wouldn't it
|
Mark M. |
?
|
Mark M. |
it's a method call
|
EGHDK |
Doesn't finish end the activity?
|
Mark M. |
finish() *schedules* the end of the activity
|
EGHDK |
...?
|
EGHDK |
How does it know when to end then?
|
Mark M. |
moreover, short of an exception, there's no way for it to skip the rest of the statements
|
Mark M. |
finish() puts an event on the message queue processed by the main application thread
|
Mark M. |
when that message bubbles to the top, the activity begins the shutdown process (onPause(), etc.)
|
EGHDK |
Puts an event on the "end" of the message queue?
|
EGHDK |
Cool. Gotcha.
|
Mark M. |
presumably at the end, though I haven't looked
|
Mark M. |
it doesn't matter vis a vis your question
|
EGHDK |
So for example, I'm in MainActivity, and I want to
finish MainActivity because I want it to start again. Is it proper to
call startActivity(intent); before finish()?
|
EGHDK |
Or the other way around? Or does it not even matter?
|
Mark M. |
that's the typical approach, though AFAIK the reverse order would still work
|
EGHDK |
Okay, next question. I've been working a lot with databases and reading a lot into your SQLite tutorials.
|
Jun 27 | 7:30 PM |
EGHDK |
I'm having trouble with the Async stuff, but for now I'm just trying to do simple CRUD actions.
|
EGHDK |
Mostly because there are many ways to do CRUD.
|
EGHDK |
I followed your technique and simply extended a
SQLiteOpenHelper, but a lot of people create a Data class, and then
create a class inside of that. Is any way better than another?
|
EGHDK |
If that makes sense...
|
Mark M. |
what's "a Data class"?
|
EGHDK |
Just like AppData.java and then within that they have a class that extends SQLiteOpenHelper.
|
Mark M. |
I can't really comment on what's better
|
Mark M. |
that would require me to have seen examples of your pattern and remember what they look like
|
Mark M. |
suffice it to say, there are any number of ways to organize the CRUD code
|
Mark M. |
and I'm not aware of any specific "better" or
"worse" approach among them, so long as they're doing the work
asynchronously by one means or another
|
Jun 27 | 7:35 PM |
EGHDK |
Well I'm basically just a bit confused, because in this video https://www.youtube.com/watch?v=c5n90wiv75M if you pause at 16:26 you see the code I'm talking about.
|
Mark M. |
again, I cannot really comment on it
|
EGHDK |
Sorry for the link, idk if you "accept" that on the chat.
|
Mark M. |
links are fine, though reviewing source code by YouTube video is not especially practical
|
EGHDK |
Hahah true.
|
Mark M. |
I doubt there's anything substantially wrong with what they're doing
|
EGHDK |
Okay, so hopefully you can comment on this. I have
a database with multiple tables. What would be the best way to set that
up? One DBHelper class?
|
Mark M. |
well, it's one SQLiteOpenHelper per database, regardless of the number of tables
|
Mark M. |
in terms of where your CRUD methods go, I'd argue that it would depend a bit more on what sort of Java API you need
|
Mark M. |
for example, if there are multiple tables, but
you're converting the SQLite data to/from POJOs, there might be a single
class responsible for persisting and loading the POJOs
|
EGHDK |
Ideally, I'll be using about 2 or three tables constantly. SO I need to go back and look at your Async DB code.
|
Mark M. |
if, OTOH, you are sticking more with Cursors as
what you're loading and putting in the UI, then one DBHelper per table
may make more sense
|
Mark M. |
my database samples are mostly designed to show how to run the code
|
Mark M. |
code organization techniques vary by project size and other characteristics that exceed the scope of my samples
|
Jun 27 | 7:40 PM |
Mark M. |
where there are functional aspects (e.g., threading), my samples are probably fairly good
|
EGHDK |
I believe I looked through your samples a few
times and I still had trouble on inserting into the database, outside of
the DBHelper class.
|
Mark M. |
I can't really comment on "trouble" without more specifics, sorry
|
EGHDK |
In your sqlite section, you only show insert statements inside of the oncreate and inside of an async task.
|
EGHDK |
Oh. Is that because it should only be done in OnCreate or inside of an async task! =)
|
EGHDK |
?
|
Mark M. |
certainly, inserts should be done in a background thread
|
EGHDK |
I'm a genius.
|
EGHDK |
Hahaha. It only took me the time to write down the question, and ask you the question, for it to actually hit me.
|
Mark M. |
onCreate() of a SQLiteOpenHelper is hopefully
being called on a background thread, by virtue of your calling
getReadableDatabase() or getWriteableDatabase() on a background thread
|
EGHDK |
That's why you don't show how to do it anywhere else. Aww man. Sweet.
|
Jun 27 | 7:45 PM |
Mark M. |
now, it doesn't strictly have to be an AsyncTask -- any sort of background thread would work
|
Mark M. |
(e.g., IntentService)
|
EGHDK |
Okay, couple more questions then. If I'm going to be accessing my database a lot should I open it once, and not close it often?
|
Mark M. |
yes
|
EGHDK |
Okay, cool. Next question. I do this quite often. I
take a button and give it a white background, so it immediately loses
that gray button color. It also loses touch feedback. Is there anyway to
add touch feedback without creating a new file for it?
|
Mark M. |
it's more that if you want to change the background, you cannot just call setBackgroundColor()
|
Mark M. |
what makes a Button work like a Button is the background
|
Mark M. |
which is a StateListDrawable
|
Mark M. |
hence, the only way to really change the
background color *and* keep it working like a Button is to replace the
StateListDrawable with another StateListDrawable
|
Mark M. |
where you change the images for the relevant states to be your desired color
|
EGHDK |
I could've sworn I saw some xml attribute that will add that blue glow to any button. Or am I just imagining things?
|
Mark M. |
AFAIK, you are imagining things
|
EGHDK |
Maybe its the weather. Flash floods and such. You should be fine in PA hopefully!
|
Mark M. |
BTW, I think the Android Holo Colors generator can help you with this
|
Mark M. | |
Jun 27 | 7:50 PM |
EGHDK |
Yeah thanks.
|
EGHDK |
So I really don't use styles.xml
|
EGHDK |
Should I start? I mean when I do web design, I
always use styles.css. But I never feel the need to. I always just hard
code changes to stuff in xml. Thats pretty bad right?
|
Mark M. |
I wouldn't say it's "pretty bad"
|
Liam | has entered the room |
Mark M. |
in Web development, you often inline CSS style rules, for one-off divs and the like
|
Mark M. |
where the CSS dedicated files come in is for styles you're repeating across multiple spots
|
Mark M. |
(BTW, howdy, Liam -- be with you in a minute!)
|
Mark M. |
for widgets that allow adjusting UI both via attributes and via styles, you can take a similar approach
|
Liam |
Thanks Mark!
|
Mark M. |
but for something like a button background, since
you probably should be applying that same look for most/all buttons, a
style would seem apropos
|
Mark M. |
let me take a question from Liam, and I'll be back with you in a bit
|
Mark M. |
Liam: hi! do you have a question?
|
Liam |
View paste
|
EGHDK |
Alright Mark, I'm out. That was the end of my list of questions after programming for today. Thanks again.
|
Mark M. |
EGHDK: you're welcome!
|
Liam |
It works great on most phones, but prior to api 11 it doesnt show up.
|
Jun 27 | 7:55 PM |
Liam |
I think it is not supported in earlier versions ( after checking the docs)
|
Mark M. |
Liam: well, on newer Android devices, stuff that had been the options menu becomes part of the action bar
|
Liam |
but i am trying to figure out a way to implement a work around
|
Mark M. |
on older Android devices, you would press the MENU button to view the options menu
|
Liam |
hmm yeah that is what i thought but when i hit the men button it seems to shut down
|
Mark M. |
what is "it", and what does "shut down" mean?
|
Liam |
Sorry, the app closes with a standard error code
|
Mark M. |
what is "a standard error code"?
|
Liam |
Application is not responding
|
Mark M. |
OK, that means that you are doing something that is tying up the main application thread
|
Mark M. |
and doing so for a substantial period of time
|
Mark M. |
that may or may not have anything really to do with the options menu
|
Mark M. |
as pressing on the MENU button may just be the trigger for Android to decide to raise the ANR, given the frozen app UI
|
Liam |
Okay, that makes sense. So just to make sure I
understand, there is nothing about the onCreateOptionsMenu or
onCreateOptionsMenu that wouldnt work on older versions, right>
|
Mark M. |
correct
|
Jun 27 | 8:00 PM |
Mark M. |
and, if you want a consistent action bar look-and-feel even on the older devices, use ActionBarSherlock
|
Liam |
Okay, thanks. Yeah, I will check that out too.
|
Liam |
Do you have time for another question?
|
Liam |
View paste
|
Mark M. |
go right ahead -- the chat runs for another half-hour, and EGHDK asked a bunch of questions earlier :-)
|
Liam |
Okay, sweet.
|
Liam |
So I writing an app that calls the following flags to wake the phone up and keep it on
|
Liam |
I also clear the flags but the phone does not go to sleep after
|
Mark M. |
it will go to sleep after the normal timeout period
|
Mark M. |
or when the user presses the power button
|
Liam |
Yeah, for some reason that is being overriden
|
Liam |
almost as if i were using the power manager's wake lock
|
Mark M. |
you might try using setKeepScreenOn() on a View, instead of FLAG_KEEP_SCREEN_ON, and see if that improves matters
|
Mark M. |
I have never tried clearing FLAG_KEEP_SCREEN_ON,
and I pretty much always use setKeepScreenOn() (and
android:keepScreenOn) rather than use that flag anyway
|
Jun 27 | 8:05 PM |
Liam |
Okay, i will give that a try. I am also calling home screen using this method. Any chance this is causing a problem?
|
Liam |
View paste
|
Mark M. |
I doubt that you need the FLAG_ACTIVITY_NEW_TASK part
|
Mark M. |
otherwise, I would not expect that to represent any sort of problem
|
Liam |
Okay, thanks.
|
Mark M. |
EGHDK: if you have another question, chime in
|
Mark M. |
OK, if either of you have a question, chime in
|
Jun 27 | 8:10 PM |
Liam |
Mark- any way or program you recommend to test battery consumption?
|
Mark M. |
that's seriously difficult without dedicated hardware
|
Mark M. |
if you have $1000 lying around that you don't know what to do with, buy a Qualcomm MDP device and use Trepn
|
Mark M. |
at the moment, we're lacking great options for specifically measuring battery use
|
Liam |
Okay, yeah I will keep going with how hot the phone is then!
|
Mark M. |
so, you wind up focusing on CPU and radio use, etc.
|
Mark M. |
IOW, focus on the things that drain the battery, more so than the battery itself
|
Liam |
Okay, thanks! Yeah, that is why i stopped used the PowerManager
|
Liam |
That sounded like a big no no
|
Mark M. |
if you mean WakeLocks, they are safe in short stints, but not the sort of thing you want to hold a long time
|
Liam |
Yep, that is what I mean and thanks.
|
Liam |
You are good!
|
Mark M. |
I try
|
Jun 27 | 8:15 PM |
Mark M. |
and thanks!
|
Liam |
Yep! If no one has any other questions... I am
working on your setKeepScreenOn() implementation. Can I just attach to
any view in my activity?
|
Mark M. |
yes
|
Liam |
Okay, cool.
|
Jun 27 | 8:25 PM |
Mark M. |
any last questions?
|
Jun 27 | 8:30 PM |
Mark M. |
OK, that's a wrap for today's chat
|
Mark M. |
next chat is Monday at 10am Eastern
|
Mark M. |
this chat's transcript will be posted shortly to http://commonsware.com/office-hours/
|
Mark M. |
have a pleasant day!
|
Liam |
Thanks!!
|
EGHDK | has left the room |
Liam | has left the room |
Mark M. | turned off guest access |