You could do something like this.
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent intent = new Intent(getActivity().getApplicationContext(), ViewMyCommande.class);
HashMap<String, String> map = (HashMap) parent.getItemAtPosition(position);
String key = "log";
intent.putExtra("key", key);
intent.putExtra("value", map.get(key))
startActivity(intent);
}
PS: In your code you have a line like this String tid = map.get("log").toString();
as your map is already a <String, String>
map, there is no need to call Object::toString
in it. Just call String tid = map.get("log")
that will get you a String.
Another suggestion is to set this key "log"
that you are using as a constant, than accessing it from the bought Activities. You would add a field like this into your Activity class private static final String MAP_KEY = "log";
than you could use it in you code, so in the code above, you could remove the String key = "log";
line and replace key
by your constant, so the two intent lines would look like this:
intent.putExtra("key", MAP_KEY);
intent.putExtra("value", map.get(MAP_KEY))
Another suggestion is to extract the bouth keys that you're using in putExtras as public constants, then use these in the Activity that you are receiving the data. Something like this:
public static String KEY = "key";
public static String VALUE = "value";
Then use it in the intent lines.
intent.putExtra(KEY, MAP_KEY);
intent.putExtra(VALUE, map.get(MAP_KEY))
When in you SecondActivity you can get these values as getArguments().getString(FirstActivity.KEY);
same for value.
Another observation, if your key will be constant you don't really need to send the key to your SecondActivity.
If you need all these map in your SecondActivity you could call putExtra
and place you map in it. Then in SecondActivity you would need yo call HashMap<String, String> firstActivityMap = (HashMap<String, String>) getSerializable(MAP)
OBS: maybe it's a bit confusing, I hope community could help to improve this answer