views:

37

answers:

1

I'm adding Android C2DM to a Android library project. I started with the com.google.android.c2dm package that is included with JumpNote and Chrome To Phone. In order to use this package, you have to subclass the C2DMBaseReceiver service which takes the Sender Id as an argument to it's constructor. In JumpNote, this argument is initialized using a hard-coded static variable in a config class. However, in an Android library project, which may be used by multiple concurrently running apps I don't think I can use a hard-coded static variable (that is, I believe it could lead to problems when/if multiple apps are trying to access/modify the static variable).

I tried to think of a way to initialize the Sender Id without using a static variable and am stumped so far.

The obvious solution would be to use the Manifest or a Resource string or a combination of the 2. For example, in strings.xml I might have a "ac2dmSender" string, which is accessed in a meta-data child of the C2DMReceiver service declaration in the manifest. However, it seems that you cannot get a reference to the PackageManager or ResourceManager from a static context, so there is no way for me to then retrieve the meta data in such a way as to pass it in to the constructor of C2DMBaseReceiver.

Please let me know that I'm missing something! Thanks in advance.

A: 

However, in an Android library project, which may be used by multiple concurrently running apps I don't think I can use a hard-coded static variable (that is, I believe it could lead to problems when/if multiple apps are trying to access/modify the static variable).

"Multiple concurrently running apps" each have their own copy of the static variable, since each runs in its own process.

CommonsWare
So you think I should just set the static to whatever I need it to be from a subclass? Seems ugly but if it won't cause problems, great! Your answer doesn't address my question. It does, however, offer a solution to my problem so if no one else has a better idea in the next couple days I'll accept.
ajh158
@ajh158: "So you think I should just set the static to whatever I need it to be from a subclass?" -- I didn't say that. I was specifically addressing your static concerns. I have not examined the Google C2DM code enough to have an opinion one way or another regarding the use of the static data member. Sorry!
CommonsWare
Sorry, I didn't mean to put words in your mouth. I appreciate your response and it helped me consider the problem with new information. I made some code changes that have let me move forward, but I'm still waiting for an answer to my question - still planning on accepting your if I dont get one.
ajh158