Static variables or passing variables via bundles?… here is a solution to the problem.
Static variables or passing variables via bundles?
Let’s say I have a ListView and set an OnItemClickListener in the list. What is the best way to pass variables?
Static variables:
public static String example;
onItemClick
Intent intent = new Intent(Main.this, Details.class);
Main.example = "example";
startActivity(intent);
in onCreate of Details
String example = Main.example;
bundle :
// onItemClick
Intent intent = new Intent(Main.this, Details.class);
intent.putExtra("example","example");
startActivity(intent);
in onCreate of Details
Bundle extras = getIntent().getExtras();
String example = extra.getString("example");
or
Intent intent = getIntent();
String example = intent.getStringExtra("example");