0
第一個活動我想打開兩個其他活動,然後我想在活動A.on活動一個我打開活動乙還有我打開活動從活動C均扮演選定的歌曲C。 我想播放精選歌曲活動C。先從onActivityResult
但我不明白。怎麼了? 非常感謝,Vinzenz :)
這是ActivityA:
LinearLayoutBrowse.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
Intent i = new Intent(getApplicationContext(), BrowseActivity.class);
startActivityForResult(i, 100);
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
mDrawerLayout.closeDrawers();
}
}, 300);
}
});
@Override
protected void onActivityResult(int requestCode,
int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(resultCode == 100){
currentSongIndex = data.getExtras().getInt("songIndex");
//drawerclose
// play selected song
playSong(currentSongIndex);
}
}
這是ActivityB:
LinearLayoutTitel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
myViewFlipper.showPrevious();
Intent i = new Intent(BrowseActivity.this, AllSongs.class);
startActivityForResult(i, 100);
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// this is the data that comes back from Activity C when Activity C calls finish()
// set the data as the result
setResult(???);
// then you can finish
finish();
}
這是ActivityC:
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// getting listitem index
int songIndex = position;
// Starting new intent
Intent in = new Intent(getApplicationContext(),
MainActivity.class);
// Sending songIndex to BrowseActivity
in.putExtra("songIndex", songIndex);
setResult(100, in);
// Closing PlayListView
finish();
}