Mark M. | has entered the room |
Feb 21 | 9:55 AM |
Mark M. | turned on guest access |
Ron B. | has entered the room |
Mark M. |
hello, Ron!
|
Mark M. |
how can I help you today?
|
Feb 21 | 10:00 AM |
Ron B. |
Hi Mark. Trying to get an API key for MapsV2 that covers both debug and deployment. I'm on page 1035 of your 5.6 book. Don't see "Registered Apps" on the left navigation bar of the Google Cloud Services
|
Mark M. |
yeah, they changed that site, again
|
Mark M. |
(grumble, grumble, grumble)
|
Mark M. |
hold on a second while I pull it up
|
Mark M. |
click "Credentials" in the "APIs & auth" area
|
Mark M. |
if you have enabled the Maps V2 API (in "APIs" under "APIs & auth"), you should have a red "CREATE NEW KEY" button
|
Mark M. |
that will pop up a dialog where you can enter signing key/package name pairs
|
Mark M. |
(after first choosing "Android key")
|
Ron B. |
So far, so good. Got the enter pairs screen...
|
Feb 21 | 10:05 AM |
Mark M. |
fill them in, click "Create", and you're set
|
Ron B. |
So I have to run keytool against my keystore(s)?
|
Mark M. |
to get the signing key fingerprint, yes
|
Mark M. |
that's covered in "Your Signing Key Fingerprint(s)", on the previous page of the book
|
Mark M. |
I have the command there for the debug keystore; you'd substitute your own path, alias, and passwords for production keystores
|
Feb 21 | 10:10 AM |
Ron B. |
So I do this twice, once for debug keystore, once for deployment keystore and get a single API key back?
|
Mark M. |
if "this" is "run keytool", then yes
|
Mark M. |
you can paste in both pairs (debug fingerprint + package, production fingerprint + package)
|
Mark M. |
this allows you to use one API for both builds
|
Mark M. |
and saves having to mess around with swapping API keys between debug and production
|
Mark M. |
which was a serious pain in various body parts back in the Maps V1 days...
|
Ron B. |
Great. That's what I was hoping for. It will take me a while to work through it.
|
Ron B. |
Today, I wish there were more people for you to talk to ....
|
Mark M. |
it's an unusual time slot
|
Mark M. |
most chats are Tuesday and Thursday
|
Mark M. |
I am unavailable next week, so I added a third chat this week
|
Feb 21 | 10:15 AM |
Mark M. |
if you have another question, go right ahead
|
Ron B. |
No, I'm all set for now. I have to work through getting the fingerprints. Not that urgent, if I have issues I can wait a couple of weeks. Thanks!!
|
Feb 21 | 10:25 AM |
EGHDK | has entered the room |
Mark M. |
hello, EGHDK!
|
Mark M. |
EGHDK: do you have a question?
|
EGHDK |
Yep.
|
Feb 21 | 10:30 AM |
EGHDK |
I have two activities and one custom class on top of that in my app. When I go from activity A to B, I create a new CustomClassObject and I pass it a context. In this class, I use the context to finish activity B when something happens. My problem is that I'm using a static variable in activity B and even though I have finished activity B, if I go back, my static variable is still set to whatever I have changed it to. Hope that wasn't too confusing.
|
Mark M. |
that's how static data members work in Java
|
Mark M. |
what are you expecting to happen?
|
EGHDK |
Okay, let me expalin again and what I thought was going to happen.
|
Feb 21 | 10:35 AM |
EGHDK |
Go from activity A to B. In B I have a static data member, that get's toasted when the activity Resumes (just so I can check the value of the static variable. I finish the activity, and I'm back at A. I open B from A again, and it still has that static member set to what it was before. In my head. The Activity was finished, so none of the variables in there should exist anymore, therefor when creating a new intent, I should get a new instance of this static variable.
|
Mark M. |
why did you make it static?
|
Mark M. |
the behavior you describe is for a *regular* data member, not a static one
|
Mark M. |
sorry, I meant "the behavior you want"
|
EGHDK |
Well, I need to access the static member from the customclass I told you about.
|
EGHDK |
I kind of understand why the static variable sticks around... but that got me thinking. Does that mean that ENTIRE activity B is still in memory?
|
Mark M. |
no, you need to access the *data* from the custom class
|
Mark M. |
you *chose* to use some static data member to do that
|
Feb 21 | 10:40 AM |
Mark M. |
you are welcome to choose something else
|
Mark M. |
for example, make it a *regular* data member, with a getter method (getWhateverTheHellThisIs())
|
Mark M. |
then, have your custom class hold a reference to the activity
|
Mark M. |
or, simply pass the data into the custom class in its constructor
|
Mark M. |
and I'm sure there are other possible patterns, but since I do not know anything much about this "custom class", I cannot advise you further
|
Mark M. |
in terms of whether your instance of Activity B is still in memory, I don't know, because I have no idea what this static data member is
|
EGHDK |
It's just an int.
|
Mark M. |
then that will not hold a reference back to the Activity B instance
|
Mark M. |
and so the Activity B instance is not reachable from this static data member
|
EGHDK |
But if it were something else... does that mean my instance of B would still be in memory?
|
Mark M. |
it depends upon what "something else" is
|
EGHDK |
Any examples?
|
EGHDK |
Would it just have to be an object?
|
Mark M. |
if "something else" holds a reference back to the instance of Activity B, then yes, the static data member will be able to reach the Activity B instance, and the Activity B instance cannot be garbage-collected
|
Mark M. |
so, for example, if you inflate a layout in Activity B, and take a widget from that layout (findViewById()), and put that widget into a static data member, you're in trouble
|
Mark M. |
because widgets hold the activity they belong to
|
Mark M. |
and so the static data member references the widget, which references the activity
|
Mark M. |
and therefore the activity cannot be garbage collected
|
EGHDK |
How do I know what objects hold the activity they belong to?
|
Feb 21 | 10:45 AM |
Mark M. |
in most cases, because you wrote the class in question
|
Mark M. |
this is why using static data members is risky
|
Mark M. |
and needs to be done carefully
|
EGHDK |
So lets say I want to use ActivityB.getMyInt() in my custom class. instead of using a static.
|
EGHDK |
How would I know I'm using the correct instance of ActivityB?
|
Mark M. |
well, where does this instance of this "custom class" live?
|
Mark M. |
is it too a static data member somewhere?
|
EGHDK |
The custom class was started in Activity B.
|
Mark M. |
that does not really answer my question
|
Mark M. |
is the instance of the custom class being referenced from a static data member of Activity B?
|
Mark M. |
or a regular data member of Activity B?
|
EGHDK |
Regular
|
Mark M. |
then how would it ever know about any *other* instance of Activity B?
|
Feb 21 | 10:50 AM |
Mark M. |
you wrote the code
|
Mark M. |
you see where you are teaching this custom class instance about the instance of Activity B
|
EGHDK |
That's actually a great point.
|
EGHDK |
Never thought of it that way.
|
EGHDK |
"then how would it ever know about any *other* instance of Activity B?"
|
EGHDK |
I always actually felt indifferent about doing that, because I thought it was creating a new object, and getMyInt from that new object.
|
EGHDK |
That makes sense. Thanks Mark.
|
Mark M. |
if anyone has another question, chime in
|
EGHDK |
So in Activity B I have a method called getMyInt. In activity B I create an CustomClassObject(Context), and then in my CustomClassObject I simply do (ActivityB) ctx.getMyInt(); and that should be it.
|
Mark M. |
even better would be to just hold onto ActivityB directly
|
Mark M. |
rather than pretending it is merely a Context, then casting it back to an ActivityB instance
|
EGHDK |
Aha. Even better.
|
Mark M. |
but, yes, the mechanics are pretty much what you describe
|
Feb 21 | 10:55 AM |
EGHDK |
So my constructor in my class should be requesting an Activity as an argument or an ActivityB as an argument?
|
Mark M. |
ActivityB
|
Mark M. |
after all, you *need* it to be an ActivityB to be able to call getMyInt() on it
|
Mark M. |
it does you no good to be passed some other Activity subclass
|
Mark M. |
or some other Context subclass
|
Mark M. |
so, you make as well make Java's strong typing work for you, to prevent bugs where you try passing in the wrong thing
|
EGHDK |
Ah yes. It's all coming together now.
|
EGHDK |
But even if I pass in an ActivityB as a context, and it's only asking for a context, then that activity I pass in, is STILL technically an Activity even though the constructor only asked for a context.
|
Mark M. |
sure
|
EGHDK |
Which is how it allows me to cast it back to an ActivityB if anything.
|
Mark M. |
right
|
EGHDK |
Great.
|
EGHDK |
Making progress. haha. Thanks again Mark. Almost through my first java book. I can see clearly now.
|
EGHDK |
The rain is gone.
|
Feb 21 | 11:00 AM |
Mark M. |
the rain
|
Feb 21 | 11:00 AM |
Mark M. |
is still here, though it will hopefully have passed by this evening
|
Mark M. |
:-)
|
Mark M. |
and that's a wrap for today's chat
|
Mark M. |
the transcript will be posted to http://commonsware.com/office-hours/ shortly
|
EGHDK |
Thanks. See you next week
|
Mark M. |
the next one is not until March 4
|
Mark M. |
March 4 at 4pm US Eastern Time, to be specific
|
Mark M. |
have a pleasant day, all!
|
Ron B. | has left the room |
EGHDK | has left the room |
Mark M. | turned off guest access |