Pass between activities, Fragments

3

I've been working with Activity and Fragments , of which I know how to move from one activity to another and from one fragment to another, ..... But how do I go from a fragment to an activity? Here I leave the code:)

1.- Move from one activity to another:

cambio.setOnClickListener ( new View.OnClickListener () {
            @Override
            public void onClick(View view) {
                Intent miintento= new Intent ( getApplicationContext (),PopUpTabla.class );
                startActivity ( miintento );
            }
        } );

2.- Pass from one Fragment to another:

BCliente.setOnClickListener ( new View.OnClickListener () {
            @Override
            public void onClick(View view) {
                tabla_cliente= new Tbl_Cliente ();
                FragmentTransaction transaction = getFragmentManager().beginTransaction();
                transaction.replace(R.id.content_main, tbl_cliente);
                transaction.addToBackStack(null);
                transaction.commit();
            }
        } );

3.- Moving from a fragment to an activity:

??? - help: (

4.-And I have another question, how do I go from a activity to a fragment? (my activity is a pop up, there is no problem?) ....

  • I did like that (a bit of code I do not know if it will be ok or not), I want to click on a TextView send me "back" to the previous fragment:

Intent intent = new Intent (getApplicationContext (), Frg_And_Inventario.class);

startActivity (intent);

  • and in the manifest I have it like this:

  • But I still do not get the same error:

android.content.ActivityNotFoundException: Unable to find explicit activity class {sie.progrsistepinsa.sie_android / sie.progrsistepinsa.sie_android.Herramt_Almacen.Frg_And_Inventario}; have you declared this activity in your AndroidManifest.xml?

  • Help please! : (
asked by Bloom 02.08.2018 в 23:50
source

1 answer

0

To open from an Fragment to an Activity the only way is to open it using a Intent , you must use getActivity() to get the context of la Activity containing the Fragment :

Intent intent = new Intent(getActivity(), OtraActivity.class);
startActivity(intent);

Example:

BCliente.setOnClickListener ( new View.OnClickListener () {
            @Override
            public void onClick(View view) {

             Intent intent = new Intent(getActivity(), PopUpTabla.class);
             startActivity(intent);

            }
        } );
    
answered by 03.08.2018 / 00:15
source