나는 실행중인 응용 프로그램이 있습니다. 사용자가 응용 프로그램으로 돌아갈 때 servise가 실행 중인지 확인하고 이것이 맞다면이 서비스에 연결하여 일부 데이터가있는 조각을 표시하려고 시도합니다. 데이터치명적인 예외 : java.lang.IllegalStateException : 활동이 파괴되었습니다.
private void callGPSFragment() {
...
GPSServicePresenter gpsServicePresenter = new GPSServicePresenter();
showGPSFragment(gpsServicePresenter);
통화 조각
public void showGPSFragment(GPSServicePresenter gpsServicePresenter) {
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction transaction = fragmentManager.beginTransaction();
transaction.replace(R.id.body_fragent, gpsServicePresenter);
Fragment oldFragment = fragmentManager.findFragmentByTag(SplashFragment.tag());
if (oldFragment != null) {
transaction.remove(oldFragment);
}
transaction.commitAllowingStateLoss();
}
을 조각을 만들고 채우기 - 연결이 완료되면 servise
private void connectService() {
registerFitnessReceiver();
sConn = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
if (service != null) {
callGPSFragment(status, mapWaySelections, activityType);
}
}
@Override
public void onServiceDisconnected(ComponentName name) {
}
};
Intent requestIntent = new Intent(MainActivity.this, FitnessRecordingService.class);
requestIntent.setAction(FitnessRecordingService.GET_FITNESS_RECORD_ACTION);
bindService(requestIntent, sConn, 0);
}
와 연결
Fatal Exception: java.lang.IllegalStateException: Activity has been destroyed
at android.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1433)
at android.app.BackStackRecord.commitInternal(BackStackRecord.java:687)
at android.app.BackStackRecord.commitAllowingStateLoss(BackStackRecord.java:667)
at com.fjuul.fjuul.MainActivity.showGPSFragment(MainActivity.java:712)
시도 :하지만 가끔은 이런 실수를 얻을
줄 번호는 '712'입니까? –
@ ρяσѕρєяK 예외를 기반으로 마지막으로 추측됩니다 : 'transaction.commitAllowingStateLoss(); ' – REG1
예. 사실입니다. commitAllowingStateLoss() 이후에 예외가 표시됩니다. – Devnock