- A fragment is created. It does the work. There are views that are shown or disappear during actions in the fragment.
- I switch to another enemy - replaceFragment.
- I am returning back - replaceFragment. View that are shown or disappear during actions in a fragment cease to be displayed setVisibility (View.VISIBLE) Initialization of the view takes place in onCreateView (findViewById)
Hiding and showing the View takes place in the context of Retrofit network requests: before the execution of the request, the View is hidden, and depending on the result:
private void callRequestBilling() { if (callBilleng != null && callBilleng.isExecuted()) callBilleng.cancel(); Retrofit retrofit = new Retrofit.Builder() .baseUrl("http:") .addConverterFactory(GsonConverterFactory.create()) .build(); IRtfAPI service = retrofit.create(IRtfAPI.class); callBilleng = service.calcBilling("application/json",new DeclarationWrapper())); callBilleng.enqueue( new Callback<RowDataWrapper>() { @Override public void onResponse(Call<RowDataWrapper> call, Response<RowDataWrapper> response) { RowDataWrapper calculator = response.body(); if (calculator!=null) { Double dTotalSum = 0d; String strTotalSum = roundTotalSum(dTotalSum); tvCalcSum.setText(strTotalSum); frPreCalcSum1.setVisibility(View.VISIBLE); frPreCalcError.setVisibility(View.GONE); layoutResults.setVisibility(View.VISIBLE); layoutResults.postDelayed(new Runnable() { @Override public void run() { scrollView1.setHeightBottomLayout(layoutResults.getHeight()); } }, 100); tvResultCostDelivery.setText(strTotalSum); } else { frPreCalcSum1.setVisibility(View.GONE); layoutResults.setVisibility(View.GONE); } } @Override public void onFailure(Call<RowDataWrapper> call, Throwable t) { Log.d(TAG, "Calc error: " + t.getMessage()); } } ); } public void doCalcRequest() { try { if (validateForm()) { btnWarningPodSum.setVisibility(View.GONE); btnWarningCost.setVisibility(View.GONE); frPreCalcError.setVisibility(View.GONE); frPreCalcSum1.setVisibility(View.VISIBLE); callRequestBilling(); } else { frPreCalcError.setVisibility(View.VISIBLE); frPreCalcSum1.setVisibility(View.GONE); } } catch(Exception e) { Log.d(TAG, "doCalcRequest error: " + e.getMessage()); } } In all cases (before and after the re-creation of the fragment) the request is executed successfully, only the View is not shown.
The problem is solved by creating a fragment of a singleton, but - this is not correct, in my opinion.