It is expected that onUserInteraction is being called for any user interaction. it works fine in PreferenceActivity. However, when a DialogPreference is popup, onUserInteraction is not called anymore even there is user interaction such as touch event.
It seems that DialogPreference is not the only case. Whenever Dialog is shown, it does not report the user interaction to activity.
But what can I do if I really need it. Thank You.
As far as I know, the
onUserInteraction()is simply not called while the user is interacting with a dialog (even started fromActivityin which you’re monitoring interactions).Two solutions I know are:
Subclass
Dialog/DialogPreferenceclass and overridedispatchTouchEvent().Implement
Window.Callbackinterface and set it asDialogs window callback by issuing:Note: this implementation should process all received events by calling appropriate dialog methods or handle the events in your own way (e.g. by manually calling
onUserInteraction()).Edit
You have couple of ways to get
Activityfrom the customPreferenceDialoginstance.Call
DialogPreference.getPreferenceManager()method which returnsPreferenceManager. It has agetActivity()method but it’s package-private so you would have to put your customDialogPreferenceinandroid.preferencepackage to access it.In the
PreferenceActivity.onCreate(), after inflating the preferences, usefindPreference()to find your customDialogPreferenceby key. Then cast it to your custom class and set activity tothisvia an accessor.I would go with the second option.