Office Hours — Today, June 22

Friday, June 19

Mark M.
has entered the room
Mark M.
turned on guest access
Jun 22
4:00 PM
Guy
has entered the room
EGHDK
has entered the room
Mark M.
hello, Guy!
Guy
hello\
Mark M.
how can I help you today?
Guy
InputMethodService
Mark M.
(and hello EGHDK -- Guy beat you by a couple of seconds!)
Guy: I know of InputMethodService, though I haven't written one
Guy
I need to make custom emoji IMAGE not unicode text with a keyboard
Mark M.
um, few apps will know what to do with that
Guy
how can I send an image by clicking the keyboard
yes I knwo
I need to build one
Mark M.
then what is the point of doing it, if it will not work reliably?
Guy
it is cliking the custom keyboard and sending an image
cant share intent because it isnt an activity
Mark M.
again, what is the point of writing a soft keyboard that will not work?
Guy
a client wants one :(
after researching I got to a dead end
Mark M.
then you should find another client
Guy
LOL.
thanks anyway
4:05 PM
Mark M.
the InputConnectionMethods for supplying replacement text support a CharSequence
you're welcome to try passing over a SpannedString that contains ImageSpan widgets
but unless the app the user is using *specifically* is expecting that sort of thing, the image will be ignored by the app
making the whole exercise pointless
Guy
I understand
Mark M.
and I do not know enough about InputMethodEditor to know when commitText() and setComposingText() get used
I apologize for not being of greater assistance to you
let me take a question from EGHDK, and I will be back with you in a bit
EGHDK: your turn! do you have a question?
Guy
just wanted to make sure. thanks again :)
EGHDK
Yeah mark. More of a java-ish question. Is there any way to make sure that someone has to override a method AND call the super implementation?
Mark M.
not through Java syntax
Guy
has left the room
EGHDK
I think at io, they announced an annotation for it. but I don't really know too much about annotations.
Mark M.
that's a possibility, though I haven't paid too much attention to those custom annotations
in the case of methods like `onPause()`, where if you fail to chain to the superclass you get a `SuperNotCalledException`, they are presumably using some flag
so they have some boolean wasSuperCalled=false, set that to true in the super's onPause(), and check wasSuperCalled after calling your onPause()
4:10 PM
Mark M.
if it is still false, you did not chain to the superclass, and so they throw the exception
EGHDK
gotcha. thats very helpful. thanks.
I'm sure I could look through your changelog... but have you made any book additions for io? anything regarding gcm?
Mark M.
not recently
other than to say "I
er
other than to say "I am not maintaining this chapter much"
I do need to either get it caught up with GCM 3.0 or nuke the chapter outright
EGHDK
gotcha. seems like they basically fixed gcm. no more of those workarounds people had to use.
4:15 PM
Mark M.
you have boundless optimism :-)
EGHDK
hahaha
so a question about singleton. I was reading the design patterns book and in a bullet point they say "be careful if you are using multiple class loaders; this could defeat the Singleton implementation and result in multiple instances"
I don't understand that sentence, and was wondering if it makes any sense to you
Mark M.
oh, yes, it makes sense
fortunately, 95% of the time, we don't worry about classloaders in Android
what specifically would you like to know?
EGHDK
I guess... what a class loader is?
Mark M.
as the name suggests, it loads classes
EGHDK
Is that just the moment when it loads a class?
But isn't a constructor a loader?
Mark M.
no
a classloader is responsible for reading in a class definition (e.g., out of a JAR file in a classic desktop/server Java environment)
and creating the corresponding Class object, and otherwise making the class available for use
4:20 PM
EGHDK
Hm. guess I'll look into it a bit more, because that doesn't seem to make too much sense to me.
Mark M.
let's draw an analogy
you're using a Web browser right now
the Web page that we are doing this chat in probably has some JavaScript in it
that JavaScript lives in a file on a server
the only reason why the JavaScript is executing in your browser is because something did the HTTP request to load it, then set it up in a JavaScript interpreter/runtime environment
without that "script loader", the JavaScript would sit on the server, forever lonely and unused
a classloader in Java fills the same sort of role, minus the network I/O, for loading in Java classes to the runtime environment
EGHDK
Hm. So you said you really don't encounter them in android, so it's probably not a big deal to worry about. Again, I'm just unsure of how often a class loader is used. Is a class loader used every time you "load" a class? So anytime you reference it, or create an object of it?
4:25 PM
Mark M.
"you really don't encounter them in android" -- no, I said you don't really *worry* about them in Android
"Is a class loader used every time you "load" a class? So anytime you reference it, or create an object of it?" -- yes
classically, with Dalvik, Java classes would not be loaded until referenced
now, with ART, I don't really know where and how the classloader concept comes into play
MiguelFebres
has entered the room
Mark M.
hello, Miguel!
MiguelFebres
Hello Everyone
EGHDK
Thanks. Thats helpful. So it's just when it gets loaded. Maybe I was overthinking it.
MiguelFebres
Hello Mark, I just subscribed to the CommonsWare program so I am new here
Mark M.
EGHDK: let me take a question from Miguel, and I'll be back with you in a bit
Miguel: thanks for subscribing! how can I help you today?
MiguelFebres
Thanks Mark
I developed a streaming client application in android using a service
all works as expected but, I have the problem that as soon the activity is destroyed, my service stops
I read about startservice vs bindservice but still my service stops
and this is hard to test because it could happen after 5 minutes or after 1 hour
4:30 PM
MiguelFebres
so its randomly
Mark M.
well, services don't live forever
that's why most media players use a foreground service, as they are part of the foreground user experience
MiguelFebres
ok but I am a heavy spotify user and I spotify almost never stops to stream
Mark M.
does Spotify have an icon in the status bar, from a Notification?
MiguelFebres
I would like to make my service last forever as Spotify
yes, and actually have some buttons in the notification there like play, next
Mark M.
they are using a foreground service, most likely
MiguelFebres
ok so would you say I should use a foreround service for my purpose?
*foreground service
Mark M.
again, most media players use a foreground service
there is a section on foreground services in the chapter on Notifications in the book, as you need a Notification to have a foreground service
see page 758 of Version 6.7 of the book
ideally, your Notification provides the same sorts of media controls as you see Spotify and other media players offer in their notifications
let me take another question from EGHDK, and I will be back with you shortly
MiguelFebres
ok I will read about that in the book and see if I can make it work... May I ask you another related question?
ok
Mark M.
EGHDK: do you have another question?
4:35 PM
Mark M.
EGHDK: if you come up with another question, ping me here on the chat so I can give you a turn
Miguel: back to you!
MiguelFebres
ok I am reading about that in the pdf but I would like to know something else
Mark M.
Miguel: go ahead
MiguelFebres
another issue I have with my current application is that if the application is running and streaming the music and someone call to the phone, the service stops/pause (no sure what happens exactly) and the phone rings
if the user does not answer and just ignore the call, the music from my application continue
so no problem
but if the person answer the call
and finish the call
he must go to my application by hand and press play to resume
I tested with Spotify, and the music continue after I finish the incoming call
how I can do the same with my service?
Mark M.
well, first, please consider the length of the call in your plans
4:40 PM
Mark M.
automatically resuming playback after a short call seems fine
automatically resuming playback after a longer call is risky
as the environment around the user may have changed
and it may not be appropriate to play back music at that point
particularly when it might be through a phone speaker, versus a headset or something
that being said, you will want to look at the audio focus APIs: http://developer.android.com/training/managing-...
MiguelFebres
so that is actually that Android OS decide or I must configure my service to handle that situation?
Mark M.
a little of both
MiguelFebres
ok I will take a look on that link after reading the pdf
Mark M.
I have not used these APIs, so other than I know this is the right area, I do not know the details of how best to handle your case
if either of you has a question, go right ahead
MiguelFebres
ok thanks
how long you will be here?
Mark M.
the chat runs for another ~15 minutes
4:45 PM
Mark M.
they run an hour each
4:50 PM
EGHDK
has left the room
4:55 PM
MiguelFebres
Mark, when is the next chat available?
Mark M.
the next one is 9am US Eastern tomorrow
the calendar for the chats is on the Warescription site (https://wares.commonsware.com)
MiguelFebres
ok I see, it is in the calendar
ok
Mark M.
usually, they are Tuesdays and Thursdays
it varies somewhat based on my travel schedule
MiguelFebres
Mark! Now it works!
I kill my activity and the streaming continues!
but even with a Foreground Service, Android OS can kill the service any moment right?
Mark M.
yes, though a foreground service is usually pretty durable
5:00 PM
Mark M.
it will depend on how much system RAM there is on the device
but a foreground service can often run for days
which probably is longer than you need it
MiguelFebres
ok great! that is what I was looking for
Mark M.
and that's a wrap for today's chat
the transcript will be posted to https://commonsware.com/office-hours/ shortly
MiguelFebres
thanks Mark, I will be back tomorrow for more questions
thanks
Mark M.
sounds good
have a pleasant day!
MiguelFebres
you too
MiguelFebres
has left the room
Mark M.
turned off guest access

Friday, June 19

 

Office Hours

People in this transcript

  • EGHDK
  • Guy
  • Mark Murphy
  • MiguelFebres