【发布时间】:2013-11-14 11:12:00
【问题描述】:
我有一个本地服务,我让我的程序在 onServiceConnected 方法中走得更远:
intentaudio=new Intent(this,AudioService.class);
sConn=new ServiceConnection() {
@Override
public void onServiceDisconnected(ComponentName name) {
// TODO Auto-generated method stub
bound=false;
}
@Override
public void onServiceConnected(ComponentName name, IBinder binder) {
// TODO Auto-generated method stub
audioService = ((AudioService.MyBinder) binder).getService();
bound = true;
body(); //this is the main code for the Activity - I moved it to separate method
}
};
startService(intentaudio);
bindService(intentaudio, sConn, 0);
所以,在这个活动中,我开始另一个活动:
intent=new Intent(mContext,Prayer.class);
startActivityForResult(intent,1);
第二个活动进展顺利,但是..如果我回去 - 我不知道该怎么办。
在 onActivityResult - 我需要服务连接回来,所以我应该做另一个
sConn=new ServiceConnection() {... 等等,但我怎样才能让 Activity 继续连接到服务?如您所见,整个活动都在onServiceConnected 方法中,因此它可以立即与服务交互。所以..我只是不知道该怎么办。
请帮忙!
【问题讨论】:
标签: java android service onactivityresult