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

时间:2011-11-26 13:39:54

标签: java android methods proximity

是否可以从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);

1 个答案:

答案 0 :(得分:0)

不,但您可以使用特定值添加额外的字段。活动开始时,解析额外的字段,如果找到该值,则调用所需的方法。类似的东西:

    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
    }

}

希望得到这个帮助。

相关问题