If one prints a Fragment:
println("fragment: ${Fragment()}")
it prints out:
Fragment{8d157db} (d63150f2-7497-4c04-9214-d20c3ccaba34)
Looking at the implementation of the toString()
, I can see:
public String toString() {
StringBuilder sb = new StringBuilder(128);
Class<?> cls = getClass();
sb.append(cls.getSimpleName());
sb.append("{");
sb.append(Integer.toHexString(System.identityHashCode(this)));
sb.append("}");
sb.append(" (");
sb.append(mWho);
if (mFragmentId != 0) {
sb.append(" id=0x");
sb.append(Integer.toHexString(mFragmentId));
}
if (mTag != null) {
sb.append(" tag=");
sb.append(mTag);
}
sb.append(")");
return sb.toString();
}
So the UUID
it's printing is from mWho
variable which gets generated using:
// Internal unique name for this fragment;
@NonNull
String mWho = UUID.randomUUID().toString();
Is there a way to get this value for use as the tag
when using supportFragmentManager.findFragmentByTag
? Getting it without parsing the toString
string.
I am asking this because right now I have my own custom uniqueUUID which I use for restoring a fragment using retainInstance
. If I can get the mWho
, I won't need my own custom code for the uniqueUUID.