Office Hours — Today, September 12

Thursday, September 7

Mark M.
has entered the room
Mark M.
turned on guest access
Sep 12
3:55 PM
Dimitris K.
has entered the room
Mark M.
hello, Dimitris!
how can I help you today?
4:00 PM
Dimitris K.
Hey Mark !
So I have a service and in that service im running a thread that is constantly waiting to receive data
the data is coming from a barcode scanner that is build it the device
the device is an android tablet running API 19
when the device goes to sleep mode I keep the service alive
but the thread seems to stop running
(the service is foreground with a notification)
Mark M.
are you using a partial wakelock to prevent the device from going to sleep?
Dimitris K.
im trying to use one
View paste
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
        PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Reader");
        wl.acquire();
this should be enough right ?
Mark M.
assuming that you hold the WAKE_LOCK permission, that should be fine
Dimitris K.
yep I do
Mark M.
OK, what are your specific symptoms that lead you to believe that the thread is not running?
Dimitris K.
well im logging something in the thread so I get constant logs as long as its running and when I press the power button it stops
4:05 PM
Mark M.
logging to LogCat?
Dimitris K.
yes
Mark M.
and you're getting other LogCat messages after the power button, just not yours?
Dimitris K.
ok good question I think im not getting any afterwards
Mark M.
usually, devices are fairly chatty on LogCat, so if you're getting *nothing* after pressing the power button, either LogCat itself is not reporting anything, or the device is going to sleep mode despite the wakelock
it's possible that your device just doesn't log all that much, in which case this isn't a good test
but I'd try to determine for certain whether the no-LogCat issue is unique to your app or is device-wide
Dimitris K.
I will confirm this now
regarding the thread itself
4:10 PM
Dimitris K.
I continue getting normal logs
but not from my thread anymore
Mark M.
OK, so this appears to be unique to your app
Dimitris K.
yes
View paste
mreadTh = new read_thread();
        mreadTh.start();
this is how I start the thread
Mark M.
next question: is this thread polling on something? or what is this thread really doing that is allowing you to both get data from the barcode scanner *and* log messages?
Dimitris K.
I will paste it just give me a second
there is no secret so here it is
View paste (22 more lines)
public class read_thread extends Thread {
        private int ret_receive = 0;

        @Override
        public void run() {
            while (!Thread.currentThread().isInterrupted()) {
                Log.e(TAG, "run: thread running" );
                if (mSeriport.isReady() > 0) {
                    ret_receive = mSeriport.wait_data();
                    if (ret_receive > 0) {
                        ret_receive = mSeriport.read(read_buffer, 100, 10);// 10ms read
                        if (ret_receive > 0) {
                            String insert_data = null;
                            try {
                                insert_data = new String(read_buffer, 0, ret_receive, "ISO-8859-1");
...
4:15 PM
Mark M.
you might want to add a lot more Log.e() calls in there, to see where things get stuck
for example, perhaps read() does not time out after you have pressed the power button
Dimitris K.
hmmm
this actually might be the issue
Raghavendra M.
has entered the room
Raghavendra M.
Hi mark
Dimitris K.
I will get back to you after testing a bit more Mark
Mark M.
Dmitris: OK, sounds good
Raghavendra: hi! it's your turn -- do you have a question?
Raghavendra M.
Hi mark i am raghu
yes
i am trying a design a time bar
uploaded a screenshot
its basically for room booking
how would i start doing it
seek bar
Mark M.
is the orange dot something that the user slides?
Raghavendra M.
yeah he can select time
while booking
4:20 PM
Raghavendra M.
its like a range bar
Mark M.
OK, then a SeekBar, or something derived from a SeekBar, is probably the starting point
there are quite a few of these things on the Android Arsenal
Raghavendra M.
yeah i have add a look
Mark M.
Raghavendra M.
but its tough to create labels on seek bar and range bar
with 15 min steps
Mark M.
unless your time range is fairly small, you won't have screen space for 15-minute labels
Raghavendra M.
yeah
Mark M.
personally, I would label the ends and show the currently-selected value
Raghavendra M.
ok
Mark M.
and use a discrete bar (there are a few on the Arsenal) for limiting the user to your 15-minute intervals
Raghavendra M.
how would i color them based on booking
green for available
red for booked
Mark M.
um, probably not easily :-)
Raghavendra M.
yeah
Mark M.
ideally, you colorize the bar itself (versus having some background image behind it that you're hoping will line up)
that might require modifications to the discrete bar implementations
I haven't looked at them in depth
Raghavendra M.
ok
thanks for the suggestion mark
Mark M.
those that are implemented as a true custom View will have an onDraw() method where they render the bar
and that would need to be adjusted to paint in different colors for different segments or something
Raghavendra M.
it requires a whole new component design
4:25 PM
Mark M.
possibly
Raghavendra M.
with rectangular areas
Mark M.
in which case, you are using the existing discrete bars as an inspiration for your own custom view
Raghavendra M.
ok
Mark M.
you would need to survey the existing libraries to see whether extending SeekBar is the right answer or not
Raghavendra M.
yeah
Mark M.
my guess is that some do and some do not
in the latter case, they handle the touch events themselves
Raghavendra M.
ohh
big challenge is colorring
rest is acheivable
Mark M.
well, given that you know the overall range, and you have a list of ranges/colors to apply, it's mostly a matter of converting time units to pixels
and then drawing the right color over the right area
bearing in mind that you probably need to change colors *between* the discrete seek positions, as you don't want the user to wonder what it means when 11:15 is red on the left and green on the right
Raghavendra M.
yes
Mark M.
you would want the color change to be at 11:22 or thereabouts
so each discrete seek position has a single color associated with it
it's an interesting problem
Raghavendra M.
yeah
there is no solution in git or arsenal
which is close
only to design the component
Mark M.
then use them as inspiration, and start from scratch (more or less)
4:30 PM
Raghavendra M.
ok
Mark M.
let me take another question from Dimitris, and I'll return to you shortly
Dimitris: your turn! do you have another question?
Dimitris K.
So mark my thread is killed
after pressing the power button there are no more logs from it
Mark M.
and you're sure that you're not indefinitely blocking on something?
Dimitris K.
the only thing I didnt try is having a log before my while condition
while (!Thread.currentThread().isInterrupted()) {
Mark M.
I thought that would have occurred before you pressed the power button
and that the power button press would be during the while loop
Dimitris K.
should I overide the interrupted method in the thread
and see if that is called ?
Mark M.
I have never done that, so I don't know what to expect
Dimitris K.
what about any known edge cases that can stop a thread from running
is there something like that ?
Mark M.
AFAIK, anything should result in a stack trace somewhere
4:35 PM
Dimitris K.
:/
Mark M.
you might want to create a scrap project that you can use to experiment with this
create a service, with a wakelock, with a thread, but drop the serial port I/O
do your polling-style loop, just without any actual polling of anything, only Thread.sleep(2)
(though I'd use SystemClock.sleep() on Android)
and see if you get log messages
after the power button is pressed
Dimitris K.
ok that makes sense
and if not ?
Mark M.
if the answer is no, then your wakelock is being ignored, and I don't know why
if the answer is yes, then I'm back to believing that you are blocking on the serial I/O
Dimitris K.
is there any alternative ?
of a thread
Mark M.
in either case, it probably involves discussions with the device manufacturer
I have no idea of what the expected behavior is here
for all I know, this is just how their hardware works
but, I would do the analysis to try to narrow the problem down as far as possible before trying to talk to the manufacturer
Dimitris K.
should I also try it with a ThreadPoolExecutor
can it make any dif?
Mark M.
I don't see how that can work in your case
but, if you see a path to it, you're welcome to give it a try
I doubt that it will change matters, though
4:40 PM
Dimitris K.
ok Mark thank you it seems that at least what I was trying so far is not wrong so I just have to research it further
Mark M.
well, it's "not wrong" in that I would not expect your symptoms
whether this is a good pattern for serial I/O on Android is outside my area of expertise
and I have no idea whether this is a good pattern with this particular piece of hardware
Dimitris K.
same goes for me :/
Mark M.
let me switch back to Raghavendra for a bit, and I'll try to get back to you before the chat ends
Raghavendra: your turn! do you have another question?
Raghavendra M.
last question is is there any other alternative
where we can select a time range
or a component
Mark M.
there is nothing built into Android for it, if that is what you mean
other than TimePicker
Raghavendra M.
ok
Mark M.
and that *really* does not fit your custom coloring plan
Raghavendra M.
yeah
will try it
thanks mark
Mark M.
you're welcome!
OK, if either of you have any questions, chime in, for the balance of the chat
Dimitris K.
not yet probably I will be back on your next office hour
4:45 PM
Dimitris K.
with proper investigation data
Mark M.
that will be Thursday, at 7:30pm US Eastern
Dimitris K.
that will be tough for me :D
Mark M.
the one after that is Saturday at 9am US Eastern -- friendlier time, less-friendly day
Raghavendra M.
sure will chat on thurday
Dimitris K.
friendlier time is enough for me :D
Raghavendra M.
has left the room
4:50 PM
Dimitris K.
have a nice day Mark
Mark M.
you too!
Dimitris K.
has left the room
4:55 PM
Mark M.
turned off guest access

Thursday, September 7

 

Office Hours

People in this transcript

  • Dimitris Kirakosian
  • Mark Murphy
  • Raghavendra Malgi

Files in this transcript