Java Code Examples for android.app.Application#getApplicationContext()

The following examples show how to use android.app.Application#getApplicationContext() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CustomTabsConnection.java    From delion with Apache License 2.0 6 votes vote down vote up
/** Warmup activities that should only happen once. */
@SuppressFBWarnings("DM_EXIT")
private static void initializeBrowser(final Application app) {
    ThreadUtils.assertOnUiThread();
    try {
        ChromeBrowserInitializer.getInstance(app).handleSynchronousStartup();
    } catch (ProcessInitException e) {
        Log.e(TAG, "ProcessInitException while starting the browser process.");
        // Cannot do anything without the native library, and cannot show a
        // dialog to the user.
        System.exit(-1);
    }
    final Context context = app.getApplicationContext();
    final ChromeApplication chrome = (ChromeApplication) context;
    ChildProcessCreationParams.set(chrome.getChildProcessCreationParams());
    new AsyncTask<Void, Void, Void>() {
        @Override
        protected Void doInBackground(Void... params) {
            ChildProcessLauncher.warmUp(context);
            return null;
        }
    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
    ChromeBrowserInitializer.initNetworkChangeNotifier(context);
    WarmupManager.getInstance().initializeViewHierarchy(
            context, R.layout.custom_tabs_control_container);
}
 
Example 2
Source File: CustomTabsConnection.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/** Warmup activities that should only happen once. */
@SuppressFBWarnings("DM_EXIT")
private static void initializeBrowser(final Application app) {
    ThreadUtils.assertOnUiThread();
    try {
        ChromeBrowserInitializer.getInstance(app).handleSynchronousStartup();
    } catch (ProcessInitException e) {
        Log.e(TAG, "ProcessInitException while starting the browser process.");
        // Cannot do anything without the native library, and cannot show a
        // dialog to the user.
        System.exit(-1);
    }
    final Context context = app.getApplicationContext();
    final ChromeApplication chrome = (ChromeApplication) context;
    ChildProcessCreationParams.set(chrome.getChildProcessCreationParams());
    new AsyncTask<Void, Void, Void>() {
        @Override
        protected Void doInBackground(Void... params) {
            ChildProcessLauncher.warmUp(context);
            return null;
        }
    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
    ChromeBrowserInitializer.initNetworkChangeNotifier(context);
    WarmupManager.getInstance().initializeViewHierarchy(
            context, R.layout.custom_tabs_control_container, R.layout.custom_tabs_toolbar);
}
 
Example 3
Source File: ContextHandler.java    From Android-SDK with MIT License 6 votes vote down vote up
private synchronized static Context recoverAppContextOldAndroid()
{
  try
  {
    final Class<?> activityThreadClass = Class.forName( "android.app.ActivityThread" );
    final Method method = activityThreadClass.getMethod( "currentActivityThread" );
    Object activityThread = method.invoke( null, (Object[]) null );
    final Field field = activityThreadClass.getDeclaredField( "mInitialApplication" );
    field.setAccessible( true );
    Application app = (Application) field.get( activityThread );
    return app.getApplicationContext();
  }
  catch ( Throwable e )
  {
    e.printStackTrace();
  }
  return null;
}
 
Example 4
Source File: CustomTabsConnection.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/** Warmup activities that should only happen once. */
@SuppressFBWarnings("DM_EXIT")
private static void initializeBrowser(final Application app) {
    ThreadUtils.assertOnUiThread();
    try {
        ChromeBrowserInitializer.getInstance(app).handleSynchronousStartupWithGpuWarmUp();
    } catch (ProcessInitException e) {
        Log.e(TAG, "ProcessInitException while starting the browser process.");
        // Cannot do anything without the native library, and cannot show a
        // dialog to the user.
        System.exit(-1);
    }
    final Context context = app.getApplicationContext();
    ChildProcessLauncher.warmUp(context);
    ChromeBrowserInitializer.initNetworkChangeNotifier(context);
    WarmupManager.getInstance().initializeViewHierarchy(
            context, R.layout.custom_tabs_control_container, R.layout.custom_tabs_toolbar);
}
 
Example 5
Source File: AndroidSkin.java    From Android-Skin with MIT License 5 votes vote down vote up
/**
 * 初始化
 * @param application
 * @param isApplyImmediate 是否立刻生效
 */
public void init(Application application, boolean isApplyImmediate) {
    if (application == null)
        return;
    isInited = true;
    mContext = application.getApplicationContext();
    mAndroidSkinManager = new AndroidSkinManager(application.getApplicationContext());
    if (isApplyImmediate)
        mAndroidSkinManager.loadSkinIfApply();
    AndroidSkinHook.getInstance().registerActivityLife(application);
}
 
Example 6
Source File: DoingDailyMainInit.java    From DoingDaily with Apache License 2.0 5 votes vote down vote up
@Override
public void onAppCreate(Application application) {

    appContext = application.getApplicationContext();

    initLog();
    initStorage();
    initRepository();
    initLeanCloud();
    initBugly();
    initUmengShare();
}
 
Example 7
Source File: BaseViewModel.java    From zephyr with MIT License 5 votes vote down vote up
public BaseViewModel(Application application) {
    super(application);
    mContext = application.getApplicationContext();

    injectDependencies();

    if (mDataRepository == null) {
        throw new IllegalStateException("Dependencies not fulfilled for this ViewModel.");
    }
}
 
Example 8
Source File: KUtilLibs.java    From KUtils-master with Apache License 2.0 5 votes vote down vote up
/**
 * 初始化库
 *
 * @param isDebug 是否打印日志
 * @param TAG     日志TAG
 * @param context application
 */
public static void init(@NonNull boolean isDebug, @NonNull String TAG, @NonNull Application context) {
    android.util.Log.d(TAG_, "==============您使用的KUtils版本:2.4.2==============");
    if (TAG == null || context == null) throw new RuntimeException("KUtilLibs 初始化参数均不能为空");
    appContext = context.getApplicationContext();
    if (isDebug) Log.init(TAG, true);//开启日志打印
    DialogUIUtils.init(appContext);
    OkGo.getInstance().init(context);
}
 
Example 9
Source File: GeoPackageRepository.java    From geopackage-mapcache-android with MIT License 5 votes vote down vote up
/**
 * Constructor
 * @param application the running application
 */
public GeoPackageRepository(@NonNull Application application) {
    context = application.getApplicationContext();
    manager = GeoPackageFactory.getManager(application);
    active.setValue(new GeoPackageDatabases(context, "active"));
    geos.setValue(new GeoPackageDatabases(context, "all"));
}
 
Example 10
Source File: Shaky.java    From shaky-android with Apache License 2.0 5 votes vote down vote up
/**
 * Entry point into this API.
 *
 * Registers shaky to the current application.
 */
@NonNull
public static Shaky with(@NonNull Application application,
                         @NonNull ShakeDelegate delegate,
                         @Nullable ShakyFlowCallback callback) {
    Shaky shaky = new Shaky(application.getApplicationContext(), delegate, callback);
    LifecycleCallbacks lifecycleCallbacks = new LifecycleCallbacks(shaky);
    application.registerActivityLifecycleCallbacks(lifecycleCallbacks);
    return shaky;
}
 
Example 11
Source File: GoogleApiManager.java    From ground-android with Apache License 2.0 5 votes vote down vote up
@Inject
public GoogleApiManager(
    Application app,
    GoogleApiAvailability googleApiAvailability,
    ActivityStreams activityStreams) {
  this.context = app.getApplicationContext();
  this.googleApiAvailability = googleApiAvailability;
  this.activityStreams = activityStreams;
}
 
Example 12
Source File: QPMManager.java    From QPM with Apache License 2.0 5 votes vote down vote up
public void init(Application application) {
    Utils.init(application);
    mContext = application.getApplicationContext();

    QPMSortManager.getInstance().init();
    QPMModeManager.getInstance().init();
    QPMSwitchManager.getInstance().init();
    QPMRAnalysisManager.getInstance().start(mContext, Process.myPid(), mContext.getPackageName());
}
 
Example 13
Source File: ZrtpCacheDB.java    From zrtp-java with GNU Affero General Public License v3.0 5 votes vote down vote up
public ZrtpCacheDB(Application acc, ZrtpLogger l) {
	logger = l;
	
	OpenHelper openHelper = new OpenHelper(
			acc.getApplicationContext(), logger);
	this.database = openHelper.getWritableDatabase();
	this.insertStmt = this.database.compileStatement(INSERT);
}
 
Example 14
Source File: ApplicationModule.java    From android-permission-checker-app with Apache License 2.0 4 votes vote down vote up
@Provides @Singleton @ApplicationContext Context provideApplicationContext(
    Application application) {
  return application.getApplicationContext();
}
 
Example 15
Source File: SPHelper.java    From timecat with Apache License 2.0 4 votes vote down vote up
public static void init(Application application) {
    context = application.getApplicationContext();
}
 
Example 16
Source File: PermissionsManager.java    From ground-android with Apache License 2.0 4 votes vote down vote up
@Inject
public PermissionsManager(Application app, ActivityStreams activityStreams) {
  context = app.getApplicationContext();
  this.activityStreams = activityStreams;
}
 
Example 17
Source File: NetworkModule.java    From Popular-Movies-App with Apache License 2.0 4 votes vote down vote up
@Provides
@Singleton
public FavoritesService providesFavoritesService(Application application) {
    return new FavoritesService(application.getApplicationContext());
}
 
Example 18
Source File: AppModule.java    From android-rxmvp-tutorial with Apache License 2.0 4 votes vote down vote up
public AppModule(Application application) {
  this.context = application.getApplicationContext();
}
 
Example 19
Source File: AppModule.java    From octoandroid with GNU General Public License v3.0 4 votes vote down vote up
@Provides
@Singleton
Context provideContext(Application application) {
    return application.getApplicationContext();
}
 
Example 20
Source File: ContextUtils.java    From NGA-CLIENT-VER-OPEN-SOURCE with GNU General Public License v2.0 4 votes vote down vote up
public static void setApplication(Application application) {
    sApplication = application;
    sContext = application.getApplicationContext();
}