2

I am using the google mobile backend starter https://cloud.google.com/cloud/samples/mbs/ and everything works until I want to try and send notifications from GCMintentService.java. If I call

Intent resultIntent = new Intent(this, MyActivity.class);

I get an error that MyActivity in the App module does not exist. As explained here error: package does not exist android google mobile backend starter this is because I cannot depend on a application module from a library module.

So my question is, if I want to use an intent in a library module to call an activity in an application module how do I do this? I have included some code would in case it helps for this specific example:

public void generateNotification(){
    NotificationCompat.Builder mBuilder =
            new NotificationCompat.Builder(this)
                    .setSmallIcon(R.drawable.notification_icon)
                    .setContentTitle("My notification")
                    .setContentText("Hello World!");

    // The line below is the one causing the problem with RideListActivity which is in the application module
    Intent resultIntent = new Intent(this, RideListActivity.class);
    PendingIntent resultPendingIntent =
            PendingIntent.getActivity(
                    this,
                    0,
                    resultIntent,
                    PendingIntent.FLAG_UPDATE_CURRENT
            );
    mBuilder.setContentIntent(resultPendingIntent);

    int mNotificationId = 001;

    NotificationManager mNotifyMgr =
            (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

    mNotifyMgr.notify(mNotificationId, mBuilder.build());
};
2
  • do you have 2 modules/apps ? GCMintentService.java seems in gcm-demo-client. And you want to call activity of your app (2nd module) from GCMintentService.java ? Commented Sep 29, 2014 at 20:06
  • well 3 modules but one is not involved here. GCMintentService.java is in the backend library and I want to this to start a notification, which when pressed will start an activity in the app module i.e. the user-facing side of the application Commented Sep 29, 2014 at 20:24

1 Answer 1

1

Usually you will not be making code changes to a library, you will use the library as-is in your app, and implement its interfaces or call it. The above code snippet should be running from your module, and GCM library should be used as dependency.

If you are already doing this in a module (core module), and you want to call an activity in a 2nd module (app module), then you will need to declare and use intent filters. Please see this for a sample code snippet. In this case, both these modules ("apps") will need to be running on the device for testing.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.