Skip to content
This repository has been archived by the owner on Jan 23, 2019. It is now read-only.

Commit

Permalink
Fix onAttach(Context) never called on old devices (#195)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lonami committed Apr 23, 2018
1 parent b2bf020 commit 3a82777
Showing 1 changed file with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.github.lonamiwebs.stringlate.dialogs;


import android.app.Activity;
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.Context;
Expand Down Expand Up @@ -167,6 +168,19 @@ public void onAttach(Context context) {
}
}

// Old devices don't have onAttach(Context), so onLocaleSelected remains null.
// We can implement both methods (since this is "deprecated") to avoid #195.
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
try {
onLocaleSelected = (OnLocaleSelected) activity;
} catch (ClassCastException e) {
throw new ClassCastException(activity.toString()
+ " must implement OnLocaleSelected");
}
}

//endregion

//region Events
Expand Down

0 comments on commit 3a82777

Please sign in to comment.