List of usage examples for android.app Activity getApplication
public final Application getApplication()
From source file:com.freshdigitable.udonroad.module.InjectionUtil.java
public static AppComponent getComponent(Activity activity) { return getComponent(activity.getApplication()); }
From source file:com.github.tetravex_android.TetravexApp.java
public static void injectActivity(Activity activity) { ((TetravexApp) activity.getApplication()).inject(activity); }
From source file:com.github.tetravex_android.TetravexApp.java
public static TetravexApp getApplication(Activity activity) { return (TetravexApp) activity.getApplication(); }
From source file:com.uphyca.kitkat.storage.InjectionUtil.java
/** * activity???//from ww w . j a v a 2 s . com * * @param activity activity */ public static void inject(Activity activity) { inject(acquireInjector(activity.getApplication()), activity); }
From source file:android.arch.lifecycle.ViewModelProviders.java
private static Application checkApplication(Activity activity) { Application application = activity.getApplication(); if (application == null) { throw new IllegalStateException("Your activity/fragment is not yet attached to " + "Application. You can't request ViewModel before onCreate call."); }//from w w w . j av a 2 s . c o m return application; }
From source file:svenmeier.coxswain.view.Utils.java
@SuppressWarnings("unchecked") public static <T> T getCallback(Activity activity, Class<T> callback) { if (activity != null && callback.isInstance(activity)) { return (T) activity; }/* w w w. j a v a2 s .c o m*/ Application application = activity.getApplication(); if (application != null && callback.isInstance(application)) { return (T) application; } throw new IllegalStateException("no requested parental callback " + callback.getSimpleName()); }
From source file:dagger.android.support.AndroidSupportInjection.java
private static HasSupportFragmentInjector findHasFragmentInjector(Fragment fragment) { Fragment parentFragment = fragment;/*from w w w. ja va 2s.c o m*/ while ((parentFragment = parentFragment.getParentFragment()) != null) { if (parentFragment instanceof HasSupportFragmentInjector) { return (HasSupportFragmentInjector) parentFragment; } } Activity activity = fragment.getActivity(); if (activity instanceof HasSupportFragmentInjector) { return (HasSupportFragmentInjector) activity; } if (activity.getApplication() instanceof HasSupportFragmentInjector) { return (HasSupportFragmentInjector) activity.getApplication(); } throw new IllegalArgumentException( String.format("No injector was found for %s", fragment.getClass().getCanonicalName())); }
From source file:Main.java
public static void openFeedback(Activity activity) { try {/*w w w. ja v a2 s.c o m*/ throw new Exception(); } catch (Exception e) { ApplicationErrorReport report = new ApplicationErrorReport(); report.packageName = report.processName = activity.getApplication().getPackageName(); report.time = System.currentTimeMillis(); report.type = ApplicationErrorReport.TYPE_CRASH; report.systemApp = false; ApplicationErrorReport.CrashInfo crash = new ApplicationErrorReport.CrashInfo(); crash.exceptionClassName = e.getClass().getSimpleName(); crash.exceptionMessage = e.getMessage(); StringWriter writer = new StringWriter(); PrintWriter printer = new PrintWriter(writer); e.printStackTrace(printer); crash.stackTrace = writer.toString(); StackTraceElement stack = e.getStackTrace()[0]; crash.throwClassName = stack.getClassName(); crash.throwFileName = stack.getFileName(); crash.throwLineNumber = stack.getLineNumber(); crash.throwMethodName = stack.getMethodName(); report.crashInfo = crash; Intent intent = new Intent(Intent.ACTION_APP_ERROR); intent.putExtra(Intent.EXTRA_BUG_REPORT, report); activity.startActivity(intent); } }
From source file:com.github.markzhai.react.preloader.ReactPreLoader.java
/** * Pre-load {@link ReactRootView} to local {@link Map}, you may want to * load it in previous activity./*from w w w . j a v a 2s . c om*/ */ public static void init(Activity activity, ReactInfo reactInfo) { if (CACHE_VIEW_MAP.get(reactInfo.getMainComponentName()) != null) { return; } ReactRootView rootView = new ReactRootView(new MutableContextWrapper(activity)); rootView.startReactApplication( ((ReactApplication) activity.getApplication()).getReactNativeHost().getReactInstanceManager(), reactInfo.getMainComponentName(), reactInfo.getLaunchOptions()); CACHE_VIEW_MAP.put(reactInfo.getMainComponentName(), rootView); }
From source file:Main.java
public static boolean isExistShortcut(Activity context, String authorities) { boolean isInstallShortcut = false; final ContentResolver cr = context.getContentResolver(); final Uri CONTENT_URI = Uri.parse("content://" + authorities + "/favorites?notify=true"); Cursor c = cr.query(CONTENT_URI, new String[] { "iconPackage" }, "iconPackage=?", new String[] { context.getApplication().getPackageName() }, null); if (c != null) { if (c.getCount() > 0) { isInstallShortcut = true;//from w w w .j a v a 2s . c o m } c.close(); } return isInstallShortcut; }