我有以下
对于方案1& 2,如果只通知一个Activity,因为其他Activity尚未打开,则可以,
对于方案3& 4,两个活动都已打开,但只会通知首先打开的活动。
我是否遗漏了代码中的任何内容以通知两位观察员?
public class StartActivity extends ListActivity {
.....
@Override
public void onListItemClick(ListView parent, View v, int position, long id) {
if (position == 1){
Intent myIntent = new Intent(StartActivity.this, download.class);
StartActivity.this.startActivity(myIntent);
}
if (position + 1 == 2){
Intent myIntent = new Intent(StartActivity.this, qirath.class);
StartActivity.this.startActivity(myIntent);
}
}
public class download extends ListActivity implements Observer,
OnSeekBarChangeListener {
......
private mediaManager player ;
@Override
public void update(Observable o, Object arg) {
System.out.println("download called");
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (player == null) player = getInstance();
player.addObserver(this);
}
}
public class qirath extends ListActivity implements Observer,
OnSeekBarChangeListener {
......
private mediaManager player ;
@Override
public void update(Observable o, Object arg) {
System.out.println("qirath called");
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (player == null) player = getInstance();
player.addObserver(this);
}
}
public class mediaManager extends Observable implements AudioManager.OnAudioFocusChangeListener, OnCompletionListener, MediaPlayer.OnPreparedListener,
MediaPlayer.OnErrorListener {
private static mediaManager ourInstance;
MediaPlayer player =null;
public static mediaManager getInstance()
{
if (ourInstance == null) {
ourInstance = new mediaManager();
return ourInstance;
}
else {
return ourInstance;
}
}
void createMediaPlayerIfNeeded() {
if (player == null) {
player = new MediaPlayer();
player.setOnPreparedListener(this);
player.setOnCompletionListener(this);
player.setOnErrorListener(this);
}
else
player.reset();
}
.......
public void onCompletion(MediaPlayer player) {
// media player finished current song
setChanged();
notifyObservers("c");
}
.....
}