ACTIVITY
I have the activity with the following global variables:
public String variable="";
public static final String KEYVARIABLE= "KEY";
In onCreate
I change the value of "variable":
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Intent intent=getIntent();
variable=intent.getStringExtra(KEYVARIABLE);
}
In onSaveInstanceState
add to bundle
the data that I collect in onCreate
@Override
public void onSaveInstanceState(Bundle bd) {
bd.putString(KEYVARIABLE, variable);
}
FRAGMENTO
In the fragment I have as global:
public String variable="";
public static final String KEYVARIABLE= "KEY";
In onCreate
:
variable=savedInstanceState.getString(KEYVARIABLE);
This does not work for me, since it tells me that "variable" is empty. That could be happening? How could you access the global variables of the activity from your fragment?