[英]Is it possible to call a method from an intent?
Is it possible to call a method from an Intent
? 是否可以从
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);
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. 希望能有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.