我正在制作一个包含 60 多个按钮的 Android 应用程序。每个按钮都会响应一个 Activity 。每个 Activity 都包含一个源自原始文件的声音文件、一个 TextView 和一个图像。有什么方法可以为每个按钮使用 Intent 参数吗?
例如:
Intent myIntent = new Intent(this, NewActivityClassName.class);
myIntent.putExtra("soundfile", "FirstKeyValue");
myIntent.putExtra("image", "SecondKeyValue");
myIntent.putExtra("text", "ThirdKeyValue");
startActivity(myIntent);
最佳答案
//Make方法让我们假设
public void sendMysong(String songname,String imgUrl,String text)
{
Intent myIntent = new Intent(this, NewActivityClassName.class);
myIntent.putExtra("soundfile",songname);
myIntent.putExtra("image",imgUrl);
myIntent.putExtra("text",text);
}
//现在在接收Activity中接收intent数据
Bundle extras = getIntent().getExtras();
if (extras != null) {
String fname=extras.get("soundfile");
int resID=getResources().getIdentifier(fname, "raw", getApplicationContext().getPackageName());
MediaPlayer mediaPlayer=MediaPlayer.create(this,resID);
mediaPlayer.start();
}
关于java - 使用一些声音文件启动 Intent ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25120061/