是否可以从意图调用方法?

发布于 2024-12-18 01:40:13 字数 483 浏览 3 评论 0原文

是否可以从 Intent 调用方法? 我需要调用我构建的通知方法,并且它必须在此活动中。

Intent locationNotific = new Intent("SendProximityIntent");
locationNotific.putExtra("RowID", id);
sendBroadcast(locationNotific);
PendingIntent lPendingIntent = PendingIntent.getActivity(this, 0, 
    locationNotific, 0);

lm.addProximityAlert((double) locationAlertGeoP.getLatitudeE6(),
    (double) locationAlertGeoP.getLongitudeE6(), 
    (float) 999999999,(long) 100000, lPendingIntent);

Is it possible to call a method from an Intent?
I need to call an notification method that I build and it has to be in this activity.

Intent locationNotific = new Intent("SendProximityIntent");
locationNotific.putExtra("RowID", id);
sendBroadcast(locationNotific);
PendingIntent lPendingIntent = PendingIntent.getActivity(this, 0, 
    locationNotific, 0);

lm.addProximityAlert((double) locationAlertGeoP.getLatitudeE6(),
    (double) locationAlertGeoP.getLongitudeE6(), 
    (float) 999999999,(long) 100000, lPendingIntent);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

流殇 2024-12-25 01:40:13

不,但您可以在意图中添加一个具有特定值的额外字段。当活动启动时,解析额外的字段,如果找到该值,则调用所需的方法。例如:

    localNotific.putExtra("KEY_METHOD_TO_CALL", 1);

在您的活动中:

onCreate... {
    Intent intent = getIntent();
    int value = -1;
    if (null != intent) {
        value = intent.getIntExtra("KEY_METHOD_TO_CALL", -1);
    }
    if (-1 != value) {
        //Call your method here
    }

}

希望这会有所帮助。

No, but you can put an extra field the intent with a specific value. When the activity starts, parse the extra field and, if the value is found, call the desired method. Something like:

    localNotific.putExtra("KEY_METHOD_TO_CALL", 1);

And in your activity:

onCreate... {
    Intent intent = getIntent();
    int value = -1;
    if (null != intent) {
        value = intent.getIntExtra("KEY_METHOD_TO_CALL", -1);
    }
    if (-1 != value) {
        //Call your method here
    }

}

Hope this help.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文