Good morning, I've been programming on Android for a few weeks and I'm having some problems with using getFragmentManager
.
I have read post about the termination of activities and this is what I have made clear:
Stack Over Flow Quote English 1
Also onDestroy () is not a destructor. It does not really destroy the object, it's just a method that delivers a certain state.
in addition to this:
Stack Over Flow Quote English 2
Consider then that your application will be in the background and then it dies. When you come back Android will remember that you had Fragments, for example A, B and C and the manager will recreate them and then add them.
I call the method 2 times from one of my activities, and the second time (after doing a getActivity.finish()
, recreate the activity and return to the previous fragment method), point me to null.
The point of failure is:
private BroadcastReceiver estadoIAReceiver = new BroadcastReceiver() {
//Cuando cambia el estado de indoor atlas actualizo la interfaz con sus propiedades
@Override
public void onReceive(Context context, Intent intent) {
Log.i("VFragment", "Cambio estado IA");
//Ejecutar metodo de un fragment desde una actividad
infoF = (InformacionFragment) getFragmentManager().findFragmentById(R.id.posicionamiento_layout); // <<--- AQUI!!!
infoF.actualizaInfoEstadoIA();
infoF.onResume();
}
};
E infoF
is what gives null
infoF = (InformacionFragment) getFragmentManager().findFragmentById(R.id.posicionamiento_layout);
This returns me null
I've been debugging the app and re-creating activities and fragments
is correct, so it should not point to null
.
My question is:
With the read, I have intuited that you are trying to point to the old fragment
(1 time executed), since finish
() does not really erase 100% the Activity
(and I assume that fragments
either) . How could I solve it?