Skip to content

Commit ccf31df

Browse files
committed
Init in static block
Change-Id: I80359cb8376c03f95ced84e93944543ceb50883c
1 parent 633da76 commit ccf31df

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

auth/src/main/java/com/firebase/ui/auth/data/remote/TwitterSignInHandler.java

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,15 @@
3333
public class TwitterSignInHandler extends ProviderSignInBase<Void> {
3434
static {
3535
if (ProviderAvailability.IS_TWITTER_AVAILABLE) {
36-
initializeTwitter();
36+
Context context = AuthUI.getApplicationContext();
37+
38+
// Note: this has no effect if Twitter is already initialized so it's safe to call
39+
// multiple times.
40+
Twitter.initialize(new TwitterConfig.Builder(context)
41+
.twitterAuthConfig(new TwitterAuthConfig(
42+
context.getString(R.string.twitter_consumer_key),
43+
context.getString(R.string.twitter_consumer_secret)))
44+
.build());
3745
}
3846
}
3947

@@ -46,15 +54,11 @@ public TwitterSignInHandler(Application application) {
4654
}
4755

4856
public static void initializeTwitter() {
49-
Context context = AuthUI.getApplicationContext();
50-
51-
// Note: this has no effect if Twitter is already initialized so it's safe to call
52-
// multiple times.
53-
Twitter.initialize(new TwitterConfig.Builder(context)
54-
.twitterAuthConfig(new TwitterAuthConfig(
55-
context.getString(R.string.twitter_consumer_key),
56-
context.getString(R.string.twitter_consumer_secret)))
57-
.build());
57+
// This method is intentionally empty, but calling it forces the static {} block of this
58+
// class to be executed (if it wasn't already).
59+
//
60+
// Even though it's currently safe to initialize Twitter more than once, this protects
61+
// against a future behavior change and gives a small efficiency gain.
5862
}
5963

6064
private static IdpResponse createIdpResponse(

0 commit comments

Comments
 (0)