gpt4 book ai didi

android - 使用 Intent 时在库模块中使用应用程序模块依赖

转载 作者:行者123 更新时间:2023-11-29 01:38:50 24 4
gpt4 key购买 nike

我正在使用谷歌移动后端启动器 https://cloud.google.com/cloud/samples/mbs/一切正常,直到我想尝试从 GCMintentService.java 发送通知。如果我打电话

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

我得到一个错误,应用程序模块中的 MyActivity 不存在。如此处所述 error: package does not exist android google mobile backend starter这是因为我不能依赖库模块中的应用程序模块。

所以我的问题是,如果我想使用库模块中的 Intent 来调用应用程序模块中的 Activity ,我该怎么做?我已经包含了一些代码,以防它对这个特定示例有帮助:

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());
};

最佳答案

通常您不会对库进行代码更改,您将在您的应用中按原样使用库,并实现其接口(interface)或调用它。上面的代码 fragment 应该从你的模块中运行,并且 GCM 库应该用作依赖项。

如果您已经在一个模块(核心模块)中执行此操作,并且您想在第二个模块(应用程序模块)中调用一个 Activity ,那么您将需要声明和使用 Intent 过滤器。 Please see this for a sample code snippet .在这种情况下,这两个模块(“应用程序”)都需要在设备上运行以进行测试。

关于android - 使用 Intent 时在库模块中使用应用程序模块依赖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26106011/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com