protected ExtendedAsyncTask(Activity activity) { mActivity = activity; mContext = activity.getApplicationContext(); }
/** * 跳转界面 3 * * @param activity * @param homeActivityClass */ public static void startActivity(Activity activity, Class homeActivityClass) { Intent intent = new Intent(activity.getApplicationContext(), homeActivityClass); activity.startActivity(intent); }
@Override public void onAttach(Activity activity) { super.onAttach(activity); context = activity.getApplicationContext(); try { fragmentListener = (MessageListFragmentListener) activity; } catch (ClassCastException e) { throw new ClassCastException(activity.getClass() + " must implement MessageListFragmentListener"); } }
@Override public Context context() { return this.getActivity().getApplicationContext(); }
@Override public Context context() { return getActivity().getApplicationContext(); }
private void bind(ExtraServiceImpl extraServiceImpl) { this.mActivityWeakReference = new WeakReference<Activity>(extraServiceImpl.mActivity); this.mContext = extraServiceImpl.mActivity.getApplicationContext(); this.mDownloadListener = extraServiceImpl.mDownloadListener; this.mDownloadingListener = extraServiceImpl.mDownloadingListener; this.mPermissionListener = extraServiceImpl.mPermissionInterceptor; this.mAgentWebUIController = new WeakReference<AbsAgentWebUIController>(AgentWebUtils.getAgentWebUIControllerByWebView(extraServiceImpl.mWebView)); }
/** * deprecated in API level 23, * but must remain to allow compatibility with api<23 */ @Override public void onAttach(Activity activity) { super.onAttach(activity); mContext = activity.getApplicationContext(); }
@Override public void onShowMessage(String message, String from) { if (!TextUtils.isEmpty(from) && from.contains("performDownload")) { return; } AgentWebUtils.toastShowShort(mActivity.getApplicationContext(), message); }
/** * Applies the current system configuration to the Activity. * * This can be used in conjunction with {@link RuntimeEnvironment#setQualifiers(String)} to * simulate configuration changes. * * If the activity is configured to handle changes without being recreated, * {@link Activity#onConfigurationChanged(Configuration)} will be called. Otherwise, the activity * is recreated as described [here](https://developer.android.com/guide/topics/resources/runtime-changes.html). * * @return ActivityController instance */ public ActivityController<T> configurationChange() { return configurationChange(component.getApplicationContext().getResources().getConfiguration()); }
/** * Returns the Application Context derived from the host Activity or {@code null} if this Controller * has not yet been attached to an Activity or if the Activity has been destroyed. */ @Nullable public final Context getApplicationContext() { Activity activity = getActivity(); return activity != null ? activity.getApplicationContext() : null; }
public BeepManager(Activity activity) { activity.setVolumeControlStream(AudioManager.STREAM_MUSIC); // We do not keep a reference to the Activity itself, to prevent leaks this.context = activity.getApplicationContext(); }
@Override public void onAttach(Activity host) { super.onAttach(host); EventBus.getDefault().register(this); if (app==null) { app=host.getApplicationContext(); new FetchQuestionsThread().start(); } }
@SuppressWarnings("deprecation") @NonNull public RequestManager get(@NonNull Activity activity) { if (Util.isOnBackgroundThread()) { return get(activity.getApplicationContext()); } else { assertNotDestroyed(activity); android.app.FragmentManager fm = activity.getFragmentManager(); return fragmentGet( activity, fm, /*parentHint=*/ null, isActivityVisible(activity)); } }
private void initVerticalGridView(List<DemoItem> content, GridView gridView) { LayoutInflater appInflater = LayoutInflater.from(getActivity().getApplicationContext()); ListAdapter adapter = new DemoGridAdapter(appInflater, content); gridView.setAdapter(adapter); OverScrollDecoratorHelper.setUpOverScroll(gridView); } }
private void initVerticalListView(List<DemoItem> content, ListView listView) { LayoutInflater appInflater = LayoutInflater.from(getActivity().getApplicationContext()); ListAdapter adapter = new DemoListAdapter(appInflater, content); listView.setAdapter(adapter); OverScrollDecoratorHelper.setUpOverScroll(listView); } }
@SuppressWarnings("deprecation") @Deprecated @NonNull @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) public RequestManager get(@NonNull android.app.Fragment fragment) { if (fragment.getActivity() == null) { throw new IllegalArgumentException( "You cannot start a load on a fragment before it is attached"); } if (Util.isOnBackgroundThread() || Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) { return get(fragment.getActivity().getApplicationContext()); } else { android.app.FragmentManager fm = fragment.getChildFragmentManager(); return fragmentGet(fragment.getActivity(), fm, fragment, fragment.isVisible()); } }
private void initVerticalRecyclerView(RecyclerView recyclerView) { LayoutInflater appInflater = LayoutInflater.from(getActivity().getApplicationContext()); final DemoRecyclerAdapterBase adapter = new DemoRecyclerAdapterVertical(new ArrayList<>(DemoContentHelper.getReverseSpectrumItems(getResources())), appInflater); recyclerView.setAdapter(adapter); recyclerView.setLayoutManager(new StaggeredGridLayoutManager(GRID_SPAN_COUNT, StaggeredGridLayoutManager.VERTICAL)); OverScrollDecoratorHelper.setUpOverScroll(recyclerView, OverScrollDecoratorHelper.ORIENTATION_VERTICAL); }
@Override public void onClick(View v) { cbCheck.setChecked(!cbCheck.isChecked()); int selectLimit = imagePicker.getSelectLimit(); if (cbCheck.isChecked() && mSelectedImages.size() >= selectLimit) { Toast.makeText(mActivity.getApplicationContext(), mActivity.getString(R.string.ip_select_limit, selectLimit), Toast.LENGTH_SHORT).show(); cbCheck.setChecked(false); mask.setVisibility(View.GONE); } else { imagePicker.addSelectedImageItem(position, imageItem, cbCheck.isChecked()); mask.setVisibility(View.VISIBLE); } } });
@Test public void shouldReturnSameApplicationContextEveryTime() throws Exception { Activity activity = Robolectric.setupActivity(Activity.class); assertThat(activity.getApplicationContext()).isSameAs(activity.getApplicationContext()); assertThat(activity.getApplicationContext()).isSameAs(Robolectric.setupActivity(Activity.class).getApplicationContext()); }
@Test public void usesApplicationContext() { Shortbread.create(activity); verify(activity).getApplicationContext(); verify(application).getSystemService(ShortcutManager.class); }