0
我有一個本地服務,我讓我的計劃走得更遠onServiceConnected方法:Android的java - 本地服務工作的onActivityResult()的正確方式?
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() {
...等,但如何才能讓活動繼續連接到服務?如您所見,整個活動都在onServiceConnected
方法中,因此它可以立即與服務進行交互。所以..我只是不知道該怎麼做。
請幫忙!
你看過我的問題了嗎? – user2976267
SRY從我不是明確的答案,我的本意是用重新啓動,當你使用onrestart回來以前活動的服務或重新創建活動.. – pavanmvn
好吧,聽着。這活動去onServiceConnected方法中,第二活動也適用內部onServiceConnected方法。所以,當我回到onActivityResult方法 - 我如何正確地重新啓動服務連接? – user2976267