Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

建议: BGABaseAdapterUtil 获取 Application时不要调用隐藏 API;改为让调用者传递吧。 #52

Open
790396054 opened this issue Aug 10, 2020 · 0 comments

Comments

@790396054
Copy link

BGABaseAdapterUtil 获取 Application时不要调用隐藏 API;
public class BGABaseAdapterUtil {
private static Application sApp;

static {
    Application app = null;
    try {
        app = (Application) Class.forName("android.app.AppGlobals").getMethod("getInitialApplication").invoke(null);
        if (app == null)
            throw new IllegalStateException("Static initialization of Applications must be on main thread.");
    } catch (final Exception e) {
        Log.e(BGABaseAdapterUtil.class.getSimpleName(), "Failed to get current application from AppGlobals." + e.getMessage());
        try {
            app = (Application) Class.forName("android.app.ActivityThread").getMethod("currentApplication").invoke(null);
        } catch (final Exception ex) {
            Log.e(BGABaseAdapterUtil.class.getSimpleName(), "Failed to get current application from ActivityThread." + e.getMessage());
        }
    } finally {
        sApp = app;
    }
}

}

建议让调用者传过来吧。这样很容易出问题。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant