How to disable the On Stop method?

0

I'm developing an application and I'm using 3 fragments in a slider layout. And when I slide from the first tab to the third tab, my first tab calls the onStop method and therefore everything in that fragment is destroyed.

Is there any way to break the onStop method? I wish he would not be called.

fragment:

/**
 * Created by Lucas on 01/10/2017.
 */

public class ProdutosFragment extends Fragment  {

private FirebaseDatabase firebaseDatabase;
private DatabaseReference databaseReference;
Button Filtrar;
List<String> areas = new ArrayList<String>();
RecyclerView recyclerView;
RecyclerAdapter adapter;
int i=0;
RecyclerView.LayoutManager layoutManager;
ArrayList<Produtos>arrayList=new ArrayList<>();
SearchView searchView;
ProgressDialog progressDialogFiltrar;
int conta=0;
@Nullable
@Override



public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.produtosfragment,container,false);


    String NomeSupermercado = Singleton.getInstance(getApplicationContext()).getNomeSupermercado();
    FirebaseProdutos firebaseProdutos= new FirebaseProdutos();
    FirebaseAutenticarSupermercado FirebaseAutenticarSupermercado = new FirebaseAutenticarSupermercado();
    FirebaseAutenticarSupermercado.Autenticar();
    firebaseDatabase = FirebaseDatabase.getInstance();
    databaseReference = firebaseDatabase.getReference().child("Estabelecimentos/Estabelecimentos/Supermercados/"+NomeSupermercado+"/produtos/");
    Filtrar = (Button)view.findViewById(R.id.btfiltrar);
    recyclerView=(RecyclerView)view.findViewById(R.id.recyclerview_id);
    layoutManager=new LinearLayoutManager(getApplicationContext());
    recyclerView.setLayoutManager(layoutManager);
    recyclerView.setHasFixedSize(true);
    searchView=(SearchView)view.findViewById(R.id.search);
    searchView.setSelected(false);
    searchView.clearFocus();
    searchView.setQueryHint("Cerveja, Morango, Aymoré, Bebidas etc");
    getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    closeKeyboard();

    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String newText) {
            // filter listview
            return true;
        }

        @Override
        public boolean onQueryTextChange(String newText) {



      newText= newText.toLowerCase();
                ArrayList<Produtos> newList= new ArrayList<>();
                for(Produtos produtos: arrayList){
                    String name=produtos.getProduto().toLowerCase();
                    String marca=produtos.getMarca().toLowerCase();
//                    String caracteristica=produtos.getCaracteristica().toLowerCase();
                    String categoria=produtos.getCategoria().toLowerCase();
                    if(name.contains(newText)||marca.contains(newText)||categoria.contains(newText)){
                        newList.add(produtos);
                    }
                }
                adapter.setFilter(newList);
                return true;
            }
        });


    if(adapter==null||arrayList==null||arrayList.size()<1||recyclerView==null){
        ProgressDialog prog= new ProgressDialog(getActivity());//Assuming that you are using fragments.
        prog.setTitle("Aguarde");
        prog.setMessage("Carregando os produtos");
        prog.setCancelable(false);
        prog.setIndeterminate(true);
        prog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
        prog.show();
    databaseReference.orderByChild("produto").addListenerForSingleValueEvent(new ValueEventListener() {

        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            arrayList.clear();
            adapter=null;
            recyclerView.setAdapter(null);
            areas.add(" "+"Categoria");
            for (DataSnapshot objSnapshot : dataSnapshot.getChildren()) {
                Produtos Listar= new Produtos();
                Listar = objSnapshot.getValue(Produtos.class);
                arrayList.add(Listar);
                areas.add(Listar.getCategoria());
            }
            adapter=new RecyclerAdapter(getActivity(),arrayList);
            recyclerView.setAdapter(adapter);
            prog.dismiss();
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {

        }
    });
    }


    Filtrar.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
            LayoutInflater inflater = getLayoutInflater();
            searchView.setQuery("",false);
            closeKeyboard();
            //Cria a view a ser utilizada no dialog
            ViewGroup view = (ViewGroup) inflater.inflate(R.layout.filtro, null);

            //Obtém uma referencia ao hinner
            final Spinner SpinnerCategoria = (Spinner) view.findViewById(R.id.spinnercategoria);
            //final Spinner SpinnerEspecificos = (Spinner) view.findViewById(R.id.spinnerprodutosespecificos);

            Button Limpar = (Button)view.findViewById(R.id.btlimparfiltro);
            Button Filtro = (Button)view.findViewById(R.id.btfiltrarproduto);

            builder.setView(view);

            final AlertDialog builderx=builder.show();
            Filtro.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    String Categoria = SpinnerCategoria.getSelectedItem().toString();
                    Log.d("Categoria","Categoria Escolhida"+Categoria);
                    if(Categoria.equals(" "+"Categoria")){
                        builderx.dismiss();
                    }
                    else {
                        ProgressDialog proga= new ProgressDialog(getActivity());//Assuming that you are using fragments.
                        proga.setTitle("Aguarde");
                        proga.setMessage("Estamos filtrando os produtos para você :)");
                        proga.setCancelable(false);
                        proga.setIndeterminate(true);
                        proga.setProgressStyle(ProgressDialog.STYLE_SPINNER);
                        proga.show();
                        databaseReference.orderByChild("categoria").equalTo(Categoria).addListenerForSingleValueEvent(new ValueEventListener() {

                            @Override
                            public void onDataChange(DataSnapshot dataSnapshot) {
                                arrayList.clear();
                                adapter=null;
                                recyclerView.setAdapter(null);

                                for (DataSnapshot objSnapshot : dataSnapshot.getChildren()) {
                                    Produtos Listar;
                                    Listar = objSnapshot.getValue(Produtos.class);
                                    arrayList.add(Listar);
                                    i++;
                                    Log.d("Quantidade de produtos", "Quantidade de produtos"+i);
                                }
                                adapter=new RecyclerAdapter(getActivity(),arrayList);
                                recyclerView.setAdapter(adapter);
                                proga.dismiss();
                            }

                            @Override
                            public void onCancelled(DatabaseError databaseError) {

                            }
                        });

                        builderx.dismiss();
                    }


                }
            });
            Limpar.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Limpar();
                }
            });
            HashSet<String> hashSet = new HashSet<String>();
            hashSet.addAll(areas);
            areas.clear();
            areas.addAll(hashSet);
            //Alphabetic sorting.
            Collections.sort(areas);
            final ArrayAdapter<String> categoriaAdapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_item, areas);
            categoriaAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            SpinnerCategoria.setAdapter(categoriaAdapter);

                        }
    });
    return view;
}


@Override
public void onResume() {
    super.onResume();
    Log.e("Ciclo", "Activity: Metodo onResume() chamado");
}

@Override
public void onPause() {
    super.onPause();
    Log.e("Ciclo", "Activity: Metodo onPause() chamado");
}

@Override
public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    Log.e("Ciclo", "Activity: Metodo onSavedInstanceState() chamado");
}

@Override
public void onStop() {
    super.onStop();
    Log.e("Ciclo", "Activity: Metodo onStop() chamado");
}

@Override
public void onDestroy() {
    super.onDestroy();
    Log.e("Ciclo", "Activity: Metodo onDestroy() chamado");
}

private void closeKeyboard() {
    View view = getActivity().getCurrentFocus();
    if(view!= null){
        InputMethodManager imm=(InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(view.getWindowToken(),0);
    }

}

private void Limpar() {
    Intent i = new Intent(getApplicationContext(), IndexActivity.class);

    startActivity(i);
}


}
    
asked by anonymous 11.08.2018 / 02:41

0 answers