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);
4

1 回答 1

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
    }

}

希望这有帮助。

于 2011-11-26T14:27:30.840 回答