संपादित करें: बग नहीं, लेकिन टुकड़े के ढांचे में कमी। इस प्रश्न का बेहतर उत्तर ऊपर दिए गए @Arcao द्वारा दिया गया है।
---- मूल पोस्ट ----
वास्तव में यह सपोर्ट पैकेज के साथ एक ज्ञात बग है (संपादित करें: वास्तव में बग नहीं। @ एलेक्स-लॉकवुड की टिप्पणी देखें)। बग रिपोर्ट की टिप्पणियों में चारों ओर एक पोस्ट किया गया काम संवाद के स्रोत को संशोधित करना है जैसे:
public int show(FragmentTransaction transaction, String tag) {
return show(transaction, tag, false);
}
public int show(FragmentTransaction transaction, String tag, boolean allowStateLoss) {
transaction.add(this, tag);
mRemoved = false;
mBackStackId = allowStateLoss ? transaction.commitAllowingStateLoss() : transaction.commit();
return mBackStackId;
}
ध्यान दें यह एक विशालकाय हैक है। जिस तरह से मैंने वास्तव में यह किया था वह सिर्फ मेरा अपना संवाद टुकड़ा था जिसे मैं मूल टुकड़े से पंजीकृत कर सकता था। जब उस अन्य संवाद खंड ने चीजें कीं (जैसे खारिज किया जाना), तो इसने किसी भी श्रोताओं को बताया कि यह दूर जा रहा था। मैंने इसे इस तरह किया:
public static class PlayerPasswordFragment extends DialogFragment{
Player toJoin;
EditText passwordEdit;
Button okButton;
PlayerListFragment playerListFragment = null;
public void onCreate(Bundle icicle){
super.onCreate(icicle);
toJoin = Player.unbundle(getArguments());
Log.d(TAG, "Player id in PasswordFragment: " + toJoin.getId());
}
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle icicle){
View v = inflater.inflate(R.layout.player_password, container, false);
passwordEdit = (EditText)v.findViewById(R.id.player_password_edit);
okButton = (Button)v.findViewById(R.id.ok_button);
okButton.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
passwordEntered();
}
});
getDialog().setTitle(R.string.password_required);
return v;
}
public void passwordEntered(){
playerListFragment.joinPlayer(toJoin, passwordEdit.getText().toString());
dismiss();
}
public void registerPasswordEnteredListener(PlayerListFragment playerListFragment){
this.playerListFragment = playerListFragment;
}
public void unregisterPasswordEnteredListener(){
this.playerListFragment = null;
}
}
इसलिए अब मेरे पास एक तरीका है कि प्लेयर लिस्टफ्रैगमेंट को सूचित करें जब चीजें होती हैं। ध्यान दें कि इसकी बहुत महत्वपूर्ण बात यह है कि आप unregisterPasswordEnteredListener को उचित रूप से कहते हैं (उपरोक्त मामले में जब कभी भी PlayerListFragment "चला जाता है") अन्यथा यह संवाद टुकड़ा पंजीकृत श्रोता पर तब तक कॉल करने का प्रयास कर सकता है जब उस श्रोता के पास कोई और मौजूद न हो।
onResumeFragments()
में मौजूद नहीं हैActivity
। यदि आप एक मूल का उपयोग कर रहे हैंActivity
, तो आपकोonPostResume()
इसके बजाय उपयोग करना चाहिए ।