Android 如何将捆绑包从活动传递到挂起的意图的服务?

Android 如何将捆绑包从活动传递到挂起的意图的服务?,android,service,Android,Service,我试图将一个变量(long)从一个活动传递到一个服务,我有以下几点 在活动中: myIntent = new Intent(SetAlarm.this, Service.class); pendingIntent = PendingIntent.getService( SetAlarm.this, (int)reminderId, myIntent, 0 ); AlarmManager alarmManager = (AlarmManager)get

我试图将一个变量(long)从一个活动传递到一个服务,我有以下几点 在活动中:

myIntent = new Intent(SetAlarm.this, Service.class);
pendingIntent = PendingIntent.getService(
     SetAlarm.this, 
     (int)reminderId, 
     myIntent, 
     0
);
AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);
bundle = new Bundle();
bundle.putLong("reminderId", reminderId);
myIntent.putExtras(bundle);
alarmManager.set(AlarmManager.RTC_WAKEUP, timeInMillisec, pendingIntent);
为我服务:

Bundle bundle = intent.getBundleExtra("bundle");
CurrentreminderId = (long)bundle.getLong("reminderId");

不知怎的,我就是无法抓住这个提醒的价值,有什么想法吗??非常感谢您的帮助。

这是我经常使用的并且似乎有效的工具。 试试看。您可能没有正确地获取额外信息

Intent intent = new Intent(this, SecondActivity.class);
Bundle b = new Bundle();

// see Bundle.putInt, etc.
// Bundle.putSerializable for full Objects (careful there)
b.putXXXXX("key", ITEM);  
intent.putExtras(b);
startActivity(intent);

// -- later, in Activity or service
Bundle b = this.getIntent().getExtras();
int i = b.getInt("key");
而不是

Bundle bundle = intent.getBundleExtra("bundle");
您应该这样做:

Bundle bundle = intent.getExtras();

已尝试的意图。getExtras();仍然无法将提醒ID传递给服务。谢谢,这就是我所拥有的,但是,嘿,我知道我错在哪里了!我已经把bundle放进去了,在我设置了pendingent之后,把变量放进bundle!我把它放在吊挂帐篷前后,它没有被捡起来,它起作用了!!不管怎样,谢谢你的建议,祝你编码愉快!