Android Can';是否将数据从活动传递到广播接收器?
当用户单击歌曲时,我试图将这些数据从我的活动传递到我的接收器 我的活动Android Can';是否将数据从活动传递到广播接收器?,android,Android,当用户单击歌曲时,我试图将这些数据从我的活动传递到我的接收器 我的活动 lv.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { //Other c
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//Other codes
try {
Intent intent = new Intent(getApplicationContext(), LockScreenReceiver.class);
intent.putExtra("pos", newPosition2).putExtra("songlist", mySongs).putExtra("lockSound", "lock");
startActivity(intent);
}catch (Exception e) {
Log.e(TAG, "Intent error");
}
}
当我单击我的歌曲时,我的应用程序崩溃
不确定这是否是正确的错误消息:
11-12 21:30:40.562 24747-24747/com.piersonleo.lockscreensound E/SecondScreen﹕ Intent error
首先,在manifest.xml中定义接收方
<receiver android:name="com.xxx.xxx.LockScreenReceiver" >
<intent-filter>
<action android:name="com.xxx.xxx.xxxx" />
</intent-filter>
</receiver>
请在你的问题中添加错误信息,这样更容易回答;这是对还是错。
<receiver android:name="com.xxx.xxx.LockScreenReceiver" >
<intent-filter>
<action android:name="com.xxx.xxx.xxxx" />
</intent-filter>
</receiver>
Intent i = new Intent("com.xxx.xxx.xxxx");
intent.putExtra("pos", newPosition2).putExtra("songlist", mySongs).putExtra("lockSound", "lock");
sendBroadcast(i);