android - Passing a Resource to an Activity via an Intent -


i have been trying hours pass resource 1 activity via intent.

here code 'source' activity:

           intent myintent = new intent(view.getcontext(), activity3.class);              int res = r.raw.voicefile;             myintent = myintent.putextra("soundfile", res);              startactivityforresult(myintent, 0); 

as can see, have file called voicefile in raw folder , setting res equal , passing intent. (i assuming of type int)

in receiving activity, have:

    intent sender=getintent();     int file=sender.getextras().getint("soundfile"); 

at point hoping file equal r.raw.voicefile in destination activity , use variable 'file' in mediaplayer call such:

          mediaplayer.create(getbasecontext(), file).start(); 

versus:

          mediaplayer.create(getbasecontext(), r.raw.voicefile).start(); 

my problem whenever click button source activity launches destination activity, force close.

do experts see glaringly wrong code?

try:

int file=sender.getintextra("soundfile", 0); 

i think intent.getextras() assumes have used bundle map extras in intent, have not.


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -