May I suggest 3 options
1 Option
Use Singleton, or simply set a class to Static.
public class Singleton {
private static Singleton uniqueInstance;
private Singleton() {
}
public static synchronized Singleton getInstance() {
if (uniqueInstance == null)
uniqueInstance = new Singleton();
return uniqueInstance;
}
}
Read more in: Singleton Java Project Pattern http://www.devmedia.com.br/padrao-de-projeto-singleton-em-java/26392#ixzz3FfAWD3Il
2 option
Set variables or global objects, you can create a Application class on Android and set global variables or even Singleton.
Example.
3 Option
You can pass variables or objects by Intent to other activitys or Fragments
Activity 1
Intent i=new Intent("....");
i.putExtra("TEXT", "Olá");
startActivity(i);
Activity 2
TextView text = (TextView) findViewById(R.id.text);
Bundle bundle = getIntent().getExtras();
String var_intent = bundle.getString("TEXT");
text .setText(var_intent );
Read more.
Have you tried to put in the statement of f:
public static float f = 3.5;
?– Gammeth
Yes I’ve tried thanks
– Dibai
Gutie, I’m reversing the edits here. Let’s focus on the floats problem in the other question ok? Please edit the other one focusing on this problem.
– bfavaretto
Look at my code @bfavaretto see what you can do: https://github.com/AndroidComunite/Android-Error/tree/master
– Dibai
@Gutie Who has to do it is you... There in the other question.
– bfavaretto