Jan 8 | 7:25 PM |
Mark M. | has entered the room |
Mark M. | turned on guest access |
EGHDK | has entered the room |
Mark M. |
howdy, EGHDK!
|
Mark M. |
how can I help you today?
|
EGHDK |
Hey. I am making a game where you'll get tokens on whether or not you've been in the app for a while. And while I'm designing the architecture myself... I'm left pondering the question if apis from the android system can be used against me?
|
EGHDK |
I know it's unlikely, but I'm mostly curious about SystemClock.elapsedTime()
|
EGHDK |
Can anyone change that?
|
Mark M. |
do you mean elapsedRealtime()
|
Mark M. |
?
|
EGHDK |
So that it always returns one number or something. Yes sorry. I don't have the docs open or code in front of me.
|
Mark M. |
I do not know of any way for somebody to change that, other than by rebooting the phone, and therefore starting the count-up process again
|
Jan 8 | 7:30 PM |
Mark M. |
a custom ROM could break it, but at that point, they'll have tons of expertise to break your system any number of ways
|
EGHDK |
If someone was rooted can they change the way an api call works?
|
Micalet | has entered the room |
Mark M. |
not really
|
Mark M. |
(hello, Micalet -- I will be with you shortly!)
|
Micalet |
Ok Mark
|
EGHDK |
So in a custom rom they could just change the imlementation of that method?
|
Mark M. |
sure
|
EGHDK |
They can change any methods... at that point... correct?
|
Mark M. |
sure
|
Mark M. |
I mean, their changes may break stuff, but that's their problem
|
EGHDK |
Alright. I figured the answer was probably going to be "sure" or "maybe", but that's better than a definitive "no".
|
Mark M. |
don't take this the wrong way, but it seems unlikely that somebody is going to bother hacking some custom ROM just to break your token scheme
|
Mark M. |
to use Tim O'Reilly's phrasing, your problem is not piracy, but obscurity
|
Mark M. |
let me take a question from Micalet, and I will be back with you in a bit
|
Mark M. |
Micalet: your turn! do you have a question?
|
Micalet |
yes
|
Micalet |
I have a problem with alarmManager and notifications
|
Jan 8 | 7:35 PM |
Micalet |
Can I paste here some code?
|
Mark M. |
sure, or if you prefer, paste it into some pastebin-style service and link to it here
|
Mark M. |
this chat doesn't do any syntax highlighting or the like, as it's just a chat :-)
|
Micalet |
yes, I know, but I don't have user in any service like pastebin
|
Micalet |
I'll try to paste it here
|
Micalet |
I'm using this code to start a service that search for changes in a rss feed and send a notifications if feed have changed
|
Micalet |
View paste
(12 more lines)
|
Mark M. |
your use of FLAG_CANCEL_CURRENT worries me, but, beyond that, what is your specific problem?
|
Micalet |
I like to search for updates twice a day, so that I create a method whith this code
|
Micalet |
public void Alarma(int hora, int minut, long repeticio, int id, Context context){}
|
Jan 8 | 7:40 PM |
Micalet |
and set two alarms identicall with different ids
|
Micalet |
View paste
|
Micalet |
I've tried with other flags, but the problem still is the same
|
Mark M. |
and what is the problem?
|
Micalet |
my problem is that only works one of the alarms, and doesn't fire at that times
|
Mark M. |
it is not supposed to fire at those times
|
Mark M. |
these are inexact alarms
|
Mark M. |
for all you know, the two of them could be fired within milliseconds of each other
|
Micalet |
yes, I know, but is it correct that fire at hours from specified time?
|
Mark M. |
sure
|
Micalet |
ok
|
Mark M. |
they can be invoked anywhere within the 24 hour INTERVAL_DAY window, AFAIK
|
Mark M. |
" while the overall period of the repeating alarm will be as requested, the time between any two successive firings of the alarm may vary"
|
Mark M. |
I would recommend that you use one alarm with INTERVAL_HALF_DAY
|
Micalet |
then, should I use alarmMgr.setRepeating if I want to fire at the specified times?
|
Mark M. |
well, setRepeating() is also inexact, on Android 4.4+, if your targetSdkVersion is 19 or higher
|
Micalet |
ok
|
Mark M. |
on Android 4.4+, there is no exact repeating alarm
|
Jan 8 | 7:45 PM |
Mark M. |
other than one you roll yourself, using setWindow() or setExact() and doing the repeating part yourself
|
Mark M. |
I would also recommend using FLAG_UPDATE_CURRENT, or even 0, instead of FLAG_CANCEL_CURRENT
|
Micalet |
ok, I'll change that
|
Mark M. |
in your case, since your underlying Intent extras are not changing (because you do not have any), 0 would work just fine
|
Micalet |
ok
|
Micalet |
the other problem (I told you that I have two problems with that) is that the notifications doesn't appear in devices with android>4.x, and I'm not sure if >3.x
|
Mark M. |
start by using Log calls to see whether your alarms are getting control
|
Micalet |
i'm using this code to send the notifications:
|
Micalet |
View paste
(24 more lines)
|
Mark M. |
do you see your Log.d("Notificació", "Iniciada"); calls in LogCat?
|
Micalet |
in my own device with android 2.3.7 is running correctly, but in newer devices don't
|
Micalet |
yes in my own device
|
Micalet |
in others I couldn't check it
|
Jan 8 | 7:50 PM |
Mark M. |
what happened when you tried an emulator?
|
Micalet |
I still don't tried in an emulator.
|
Mark M. |
then you may want to start there
|
Micalet |
Apparently the code is ok?
|
Mark M. |
so long as you have the VIBRATE permission, nothing leaps out at me as being a problem
|
Mark M. |
in order to debug problems, you need environments that you can test and look at LogCat, which in many cases will have to be an emulator
|
Mark M. |
here, you need to determine if your alarms are not working, or whether they are working and you are crashing somewhere in your Notification code, etc.
|
Mark M. |
let me take another question from EGHDK, and I will be back with you later
|
Mark M. |
EGHDK: your turn! do you have another question?
|
Micalet |
ok
|
EGHDK |
Is there a main timer that runs the phone? I'm guessing theres a master timer that ticks in the kernel or something, where all other time revolves around said timer?
|
EGHDK |
Is that the SystemClock()?
|
Mark M. |
there would be at least one, perhaps more, but that's way below the level of the Android SDK (and, hence, my areas of expertise)
|
EGHDK |
Got it.
|
Jan 8 | 7:55 PM |
EGHDK |
im trying to learn more about lower level stuff in android. you said last time that stuff like startActivity is asynchonous (or at least it doesn't go off right away)... but it doesn't say that in the docs. I asked you before "Then how do you know". You said "experience" and mentioned some book. Do you remember the name of that book?
|
Mark M. |
I'm not quite sure what book you're referring to
|
Mark M. |
if you're referring to a book on Android internals, that may have been Karim Yaghmour's _Embedded Android_
|
Mark M. | |
EGHDK |
I think you mentioned a book from oh Yeah. That's it
|
EGHDK |
Sweet. Thanks.
|
EGHDK |
I'm really curious about that and still trying to wrap my head around Handlers and stuff. What would you recommend for that?
|
Mark M. |
I am not aware of any book that really gets into that part of the framework in a deep fashion
|
EGHDK |
Okay. That's fine. Just curious. You can go back to Micalet
|
Mark M. |
there probably is a book that does, but there are dozens of them, and I generally don't buy or read them to avoid accidental plagiarism
|
Mark M. |
OK
|
Mark M. |
Micalet: your turn! do you have another question?
|
EGHDK |
So you just study AOSP and read the android docs?
|
Mark M. |
(EGHDK: only when I need to, for specific problems, not as light reading before bedtime :-)
|
Jan 8 | 8:00 PM |
Mark M. |
Micalet: your turn! do you have another question?
|
Micalet |
I'm trying with an emulator
|
Mark M. |
well, with a half-day interval on your alarms, that might take a while :-)
|
Micalet |
yes, of course :-D
|
Mark M. |
OK, if either of you have a question, just ask
|
Micalet |
I'll make some test with minor intervals
|
Micalet |
ok
|
Bill M. | has entered the room |
Mark M. |
howdy, Bill!
|
Bill M. |
Hola.
|
Bill M. |
:D
|
Mark M. |
Bill: we're kind in free-for-all mode right now, so if you (or anyone) has a question, go right ahead
|
Bill M. |
Any good chatter?
|
EGHDK |
Or thsi question came out on reddit today. How do you know if the docs are updated? Someone actually mentioned you in the reddit post @Mark. haha
|
EGHDK | |
Jan 8 | 8:05 PM |
Mark M. |
yes, the documentation has substantial gaps
|
EGHDK |
I think it's a valid question. Are the docs open source?
|
EGHDK |
like can you see a git history?
|
Mark M. |
they should be up as part of android.googlesource.com
|
Mark M. |
I haven't really gone looking for the docs specifically, and the JavaDocs come from the Java code itself
|
Mark M. |
yeah, here you are: https://android.googlesource.com/platform/frame...
|
EGHDK |
Got it. Yeah. I guess I'm just trying to read the docs while I'm learning and it seems that I'd just want to know if theres some other resource people use (the sort of people that write books on android use)
|
Mark M. |
this is a place where looking at the GitHub mirror may be easier, as GitHub's Web interface is much more capable than the Gitiles that Google is using
|
EGHDK |
Cool. I'll keep digging.
|
Jan 8 | 8:10 PM |
EGHDK |
Github doesn't seem to have android/platform
|
EGHDK |
I found the android project, but not the docs dir you linked to
|
Mark M. | |
EGHDK |
Thanks mark. you always have got the answers.
|
Mark M. |
not always
|
Mark M. |
but I try
|
Jan 8 | 8:15 PM |
Mark M. |
again, if anyone has any questions, go right ahead and ask
|
EGHDK |
If someone wanted to put a password entry screen for their application... how would they do it? Moving in and out of activities wouldn't require a password screen of course... so how would you accomplish this? Activity lifecycle overlaps... and application class can't tell if the user is in/or out of the app. How would you do it?
|
Mark M. |
have some sort of session singleton in the process
|
Mark M. |
that session knows when the user last authenticated
|
Jan 8 | 8:20 PM |
Mark M. |
and it knows the rules for when re-authentication is required
|
Mark M. |
activities would check with the session in onCreate() and route things accordingly (e.g., redirect to another activity, show the authentication fragment themselves)
|
Mark M. |
if the process is terminated (e.g., user puts app in the background for a while)
|
Mark M. |
then we would re-authenticate on the next startup
|
Mark M. |
as the session would be re-initialized
|
Mark M. |
leastways, that's how I'd approach it
|
EGHDK |
Session singleton in the process.... process = application class?
|
Mark M. |
no, process = process
|
Mark M. | |
Jan 8 | 8:25 PM |
EGHDK |
Wait... deffinitely confused. So where or how would you create this session singleton?
|
EGHDK |
Just as a regular class?
|
Mark M. |
static data member
|
Mark M. |
I mean, you could put it in a custom Application subclass, but I generally avoid that
|
EGHDK |
Part of what class though?
|
Mark M. |
its own class
|
EGHDK |
Okay. It's own class got it.
|
Mark M. |
call it EghdkCoolAppSession or something
|
EGHDK |
Where would you instantiate it though?
|
EGHDK |
In the Application class?
|
EGHDK |
*subclass?
|
Mark M. |
a singleton is usually lazy-instantiated via a static accessor method
|
Mark M. | |
EGHDK |
Got it.
|
EGHDK |
Once instantiated though. Since it's static... it will last as long as the process?
|
Mark M. |
correct
|
EGHDK |
Cool. So again. Lets say you have an activity, and you leave it, but in onStop() you create and start running an infinite loop in a thread for some reason.
|
EGHDK |
Can that thread leak?
|
EGHDK |
Or when the activity is killed will the threads that were created in that activity die as well
|
EGHDK |
?
|
Mark M. |
threads are pretty much always "leaked"
|
Mark M. |
if you are the one who forks the thread, you have to clean it up
|
Mark M. |
if *Android* forks the thread (AsyncTask, IntentService, etc.), then *Android* cleans it up, but only in those cases
|
Jan 8 | 8:30 PM |
EGHDK |
Gotcha.
|
Mark M. |
and that's a wrap for today's chat
|
EGHDK |
Cool. Okay. thanks for the help mark. helpful as always
|
Mark M. |
I will post the transcript soonish to https://commonsware.com/office-hours
|
Mark M. |
the next chat is Tuesday at 9am US Eastern
|
Mark M. |
have a pleasant day!@
|
EGHDK | has left the room |
Micalet | has left the room |
Bill M. | has left the room |
Mark M. | turned off guest access |