Office Hours — Today, June 9

Tuesday, June 7

Jun 9
3:50 PM
Mark M.
has entered the room
Mark M.
turned on guest access
4:00 PM
Steve S.
has entered the room
Mark M.
hello, Steve!
how can I help you today?
Steve S.
Hi Mark!
Let me upload my question...
View paste
I have a question about how to handle references to activities in the onReceive() method of a BroadcastReceiver. I am registering the BC in onResume() and unregistering it in onPause() of the activity. The onReceive() method displays a DialogFragment in response to errors and needs a reference to the activity to do that. Do I need to be concerned that the activity could be destroyed while onReceive() is being executed so the reference to the activity would no longer be valid?
4:05 PM
Mark M.
no
onReceive() is called on the main application thread
which means that, by definition, it is either happening before onResume(), in between onResume() and onPause(), or after onPause()
it cannot happen simultaneously with any of that
so, either the broadcast happens when you are not registered (and so the broadcast is ignored)
or the broadcast happens when you are registered, and so you have a valid Activity to work with
Steve S.
Great. That's very helpful.
I have one other question today about a minor point.
If I start a new activity (call startActivity()), do I need to call finish() on the old one?
Mark M.
um, "need to" is a strong term
it all depends on what you want to have happen when the user presses BACK from the second activity
Steve S.
ok
Mark M.
so, if you specifically want a BACK press from the second activity to not return to the first activity, but to go one back from that (e.g., home screen), then sure, finish() the first activity
if, OTOH, you want the second activity to return to the first activity, you would not call finish()
4:10 PM
Steve S.
Ok. And you mean BACK as opposed to UP?
Mark M.
yes, I mean BACK, as in the triangle button on the navigation bar of an Android 5.0+
and the equivalents on other environments
Steve S.
Great. Thank you so much, Mark! No other questions today.
Mark M.
ok
happy to be useful!
Steve S.
Have a great rest of your day!
Mark M.
you too!
Steve S.
Very useful! See you next time.
Steve S.
has left the room
4:15 PM
Robert U.
has entered the room
Mark M.
hello, Robert!
how can I help you today?
4:20 PM
Robert U.
Hi, Mark. I do have a couple of questions, but no time to ask them now; going to an offsite meeting in a few minutes.
Mark M.
ok
Robert U.
I just wanted to make sure I could get into the chat room and ask questions later on, tomorrow perhaps.
Mark M.
the next chat is Saturday at 9am US Eastern
Robert U.
I'm amazed no one else is here. You're a great resource for all things Android.
Yes, I see that.
Mark M.
someone was here earlier, asked two questions, and left
one downside of Campfire is that you can't scroll back to chat history from before you joined, so you can't see those chat entries, at least until I publish the full transcript
Robert U.
One of the problems I'm having has to do with BLE. I have a code snippet that works on pre-Marshmallow devices, but not Marshmallow.
I thought it was a permissions problem, but apparently not.
Mark M.
I doubt that I can help, as I have not used any of the Bluetooth APIs, but you're welcome to ask
4:25 PM
Robert U.
The other question is about permissions in Marshmallow in general. I'll ask the next time I can get into the chat, maybe Saturday.
Mark M.
ok
Robert U.
'bye, and have a good weekend.
Mark M.
you too!
4:40 PM
Robert U.
has left the room
5:00 PM
Mark M.
turned off guest access

Tuesday, June 7

 

Office Hours

People in this transcript

  • Mark Murphy
  • Robert Uomini
  • Steve S.