我将字符串作为意图附加值传递,以下方法传递了包含我希望通过意图传递的信息的参数,我可以看到“mc”和“title”中的值应该在 toasts 中:
private void addProximityAlert(int id, Double latitude, Double longitude, String title, String mc) {
Intent intent = new Intent(PROX_ALERT_INTENT);
intent.putExtra("id", id);
intent.putExtra("mc", mc);
intent.putExtra("gl", latitude);
intent.putExtra("title", title);
PendingIntent proximityIntent = PendingIntent.getBroadcast(Map.this, id, intent, 0);
lm.addProximityAlert( latitude, longitude, POINT_RADIUS, PROX_ALERT_EXPIRATION, proximityIntent );
Toast.makeText(getApplicationContext(),"INPAMAP "+intent.getStringExtra("title")+intent.getStringExtra("mc"),Toast.LENGTH_SHORT).show();
}
现在在我的下一堂课中,无论我尝试做什么,只有“mc”保留其值,其他变量始终为空,这是下一个活动:
@Override
public void onReceive(Context context, Intent intent) {
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
Intent notificationIntent = new Intent(context, Map.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
Notification notification = createNotification();
//Here I can see title is null and mc is what it should be
Toast.makeText(context,"IN PA "+intent.getStringExtra("title")+intent.getStringExtra("mc") ,Toast.LENGTH_SHORT).show();
我尝试过使用捆绑包,但这不起作用,我完全不知道为什么只有 mc 被传递,而 mc 和 title 都是字符串。我试过只传递 mc 或 title ,但仍然只有 mc 不为空。我试图更改它们传递给 addproximityAlert 方法的顺序以及它们作为附加项添加的顺序,我没有选择。我实际上想知道如何在 Eclipse 中正确调试,这样我也许可以在使用 SO 之前自己找出这些问题,但我面临着很大的时间压力。
我将不胜感激有关如何找出我的问题的建议,谢谢。