Start an app from a fragment

1

I have an app that launches a notification and another app that collects it. The problem is that the activity that collects the intent I want not to be initialized in a activity as always but I want to do it in a fragment . Do they know in any way? Thanks

    
asked by Donis 30.11.2016 в 14:59
source

1 answer

2

You have to start an Activity ( FragmentActivity ) since this is what the Fragment can contain, a Fragment can not be isolated from an Activity.

Simply perform the Fragment transaction that you want when you start the onCreate() method of the FragmentActivity.

              // Carga nuevo fragmento deseado mediante una transacción.
              Fragment nuevoFragmento = new myFragment();
              FragmentTransaction transaction = getFragmentManager().beginTransaction();
              transaction.replace(R.id.fragment_container, nuevoFragmento);
              transaction.addToBackStack(null);
              // Commit a la transacción
              transaction.commit();
    
answered by 30.11.2016 в 16:00