Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7870613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T01:40:09+00:00 2026-06-03T01:40:09+00:00

I have a C2DM receiver class that initialises the C2DM sender email in the

  • 0

I have a C2DM receiver class that initialises the C2DM sender email in the constructor.
The thing is, I need to get the senders email from a resource string and therefore I need to get the context in the constructor for the receiver

The receiver looks like this

public class C2DMReceiver extends C2DMBaseReceiver {

    public C2DMReceiver() {
        super(AppConstants.getC2DMSender(this)); // How do I get the context here?
    }

    @Override
    public void onRegistered(Context context, String registrationId)
            throws java.io.IOException { ...

The relevant code on the C2DMBaseReceiver

public abstract class C2DMBaseReceiver extends IntentService {
...
    private final String senderId;

    /**
     * The C2DMReceiver class must create a no-arg constructor and pass the 
     * sender id to be used for registration.
     */
    public C2DMBaseReceiver(String senderId) {
        // senderId is used as base name for threads, etc.
        super(senderId);
        this.senderId = senderId;
    }
...

It’s not really relevant to the question but for background purposes the reason for needing this is that the code is in a library project that is used in many android projects each of which has it’s own sender’s email address defined in a resource file. The AppConstants class has the job of reading the various resource strings and follows on from my accepted answer for a previous question here Android, Best way to provide app specific constants in a library project?

Finally for completeness the AppConstants.getC2DMSender method looks like this

public static String getC2DMSender(Context c){
    return c.getResources().getString(uk.co.the_prize_quiz.quiz_template.R.string.c2dm_sender);
}

The specific app that users this library has the responsibility of setting the c2dm_sender variable in an xml resource. So in order to get this variable I need the context

<item type="string" name="c2dm_sender" format="string">app_specific_registered_c2dm@email_address</item>

Because this is set in a resource string the specific app can set this value and the template will use it automatically.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T01:40:10+00:00Added an answer on June 3, 2026 at 1:40 am

    Add a singleton class to your library. Have a member to hold the senderid and corresponding getter and setter methods…

    public class ClassicSingleton {
       private static ClassicSingleton instance = null;
       private String mSenderId = nulll; // Your data holder
    
       protected ClassicSingleton() {
          // Exists only to defeat instantiation.
       }
    
       public static ClassicSingleton getInstance() {
          if(instance == null) {
             instance = new ClassicSingleton();
          }
          return instance;
       }
    
       /* Setter and Getter for the mAppContext member here */
       public void setSender(String sender) {
           mSenderId = sender;
       }
    
    }
    

    In your app’s activity ClassicSingleton.getInstance().setSender("SENDER_ID")

    In your C2DM class

    public C2DMReceiver() {
        super(ClassicSingleton.getInstance().getSender());
    }
    

    Try to have the app’s context as the member instead of senderId. Then you can pull any resource you need I guess.. Let me know.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an app that receives push notifications from C2DM server with a BroadcastReceiver.
I have one question about C2DM, I registered yesterday and I got email that
I have a simple c2dm message receiver class which is called whenever the device
I have the Activity running in singleTop mode and C2DM receiver. On some notification
I have a broadcast receiver (c2dm push receiver). When i receive a push, i
I'm using C2DM in my application, and I have a receiver, which sends data
i am developing app that would receive data from server any time. i have
I have a problem with C2DM service. Given that there is more than one
In manifest in application tag I have: <receiver android:name=.MyC2dmReceiver android:permission=com.google.android.c2dm.permission.SEND> <!-- Receive the actual
I have implemented c2dm and it works fine that the device receives the message

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.