UPD
Activity
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main_screen_activity); mainFragment = new MainScreenFragment(); getSupportFragmentManager() .beginTransaction() .replace(R.id.main_frame, mainFragment) .commit(); } Fragment
@Override public void onResume() { super.onResume(); 1: redraw(); 2: getAccidents(); } private void redraw(){ Accidents.getVisible() .subscribe(a -> listContent.addView( 3: Rows.getAccidentRow(getActivity(), listContent, a) )); } private void getAccidents() { startRefreshAnimation(); //ProgressBar on Accidents.updated //подписка на Subject<Boolean> .observeOn(AndroidSchedulers.mainThread()) //Для ProgressBar .subscribe(b -> { stopRefreshAnimation(); //ProgressBar off redraw(); }); Accidents.update(); //запуск сетевого запроса, который по окончанию зашлет true в подписку строкой выше } In steps:
- Running the application. Everything works out without problems.
- I close the application with the
backbutton. - I restart.
- Line
1:executes. - Line
2:fulfills, but in line3:this timegetActivity()returnsnull
Actually the question is why with the same code the jamb occurs exactly when the application is restarted?
getSupportFragmentManager().findFragmentById(R.id.main_frame) != null- Juriy Spb ♦onCreateActivityandonAttachgetActivity()returnsnull- rjhdbygetActivity()receipt to thegetActivity()methodonResume()and assign the class field there. In the future, refer to this field, and not through the method. If it does not help, I propose to exclude calls to RxJava constants and check the status of thegetActivity()method, I am pretty sure that there will be no problem. If so, then the problem must be sought in the Rx itself - pavlofff