2011-10-24 14 views
0

私はサービスへの活動から(長い)変数を渡すためにしようとしています、私は活動で を以下している:私のサービスで保留中のインテントからアクティビティからサービスにバンドルを渡すにはどうすればよいですか?

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

、私はちょうどこの思い出された価値、アイデアをつかむことができませんでしたか?どんな助けでも大いに感謝されます、ありがとうヒープ。

答えて

1

私はいつも使っているもので、うまくいくようです。 試してみてください。エクストラを間違って取得している可能性があります。あなたがこれを行う必要があります

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"); 
+1

をおかげで、それは私が持っていたもののようなものが、花粉症だ、私は私が間違って行ってきたところを知っています!私はpendingIntentを設定した後、バンドルを入れて変数をバンドルに入れました!そして、それは私が保留中のものの前に置いた後、拾わなかった、それは働いた!とにかく、幸せなコーディングのすべての提案ありがとう! – Chungandroid

0

代わりの

Bundle bundle = intent.getBundleExtra("bundle"); 

Bundle bundle = intent.getExtras(); 
+0

試したintent.getExtras();それでもリマインダをサービスに渡すことができませんでした。 – Chungandroid

関連する問題