android.app.Activity.getApplicationContext()方法的使用及代码示例

x33g5p2x  于2022-01-15 转载在 其他  
字(7.2k)|赞(0)|评价(0)|浏览(197)

本文整理了Java中android.app.Activity.getApplicationContext()方法的一些代码示例,展示了Activity.getApplicationContext()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Activity.getApplicationContext()方法的具体详情如下:
包路径:android.app.Activity
类名称:Activity
方法名:getApplicationContext

Activity.getApplicationContext介绍

暂无

代码示例

代码示例来源:origin: k9mail/k-9

protected ExtendedAsyncTask(Activity activity) {
  mActivity = activity;
  mContext = activity.getApplicationContext();
}

代码示例来源:origin: JessYanCoding/MVPArms

/**
 * 跳转界面 3
 *
 * @param activity
 * @param homeActivityClass
 */
public static void startActivity(Activity activity, Class homeActivityClass) {
  Intent intent = new Intent(activity.getApplicationContext(), homeActivityClass);
  activity.startActivity(intent);
}

代码示例来源:origin: k9mail/k-9

@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");
  }
}

代码示例来源:origin: android10/Android-CleanArchitecture

@Override public Context context() {
 return this.getActivity().getApplicationContext();
}

代码示例来源:origin: android10/Android-CleanArchitecture

@Override public Context context() {
 return getActivity().getApplicationContext();
}

代码示例来源:origin: Justson/AgentWeb

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));
}

代码示例来源:origin: TeamNewPipe/NewPipe

/**
 * 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();
}

代码示例来源:origin: Justson/AgentWeb

@Override
public void onShowMessage(String message, String from) {
  if (!TextUtils.isEmpty(from) && from.contains("performDownload")) {
    return;
  }
  AgentWebUtils.toastShowShort(mActivity.getApplicationContext(), message);
}

代码示例来源:origin: robolectric/robolectric

/**
 * 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());
}

代码示例来源:origin: bluelinelabs/Conductor

/**
 * 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;
}

代码示例来源:origin: journeyapps/zxing-android-embedded

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();
}

代码示例来源:origin: commonsguy/cw-omnibus

@Override
public void onAttach(Activity host) {
 super.onAttach(host);
 EventBus.getDefault().register(this);
 if (app==null) {
  app=host.getApplicationContext();
  new FetchQuestionsThread().start();
 }
}

代码示例来源:origin: bumptech/glide

@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));
 }
}

代码示例来源:origin: EverythingMe/overscroll-decor

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);
  }
}

代码示例来源:origin: EverythingMe/overscroll-decor

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);
  }
}

代码示例来源:origin: bumptech/glide

@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());
 }
}

代码示例来源:origin: EverythingMe/overscroll-decor

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);
}

代码示例来源:origin: jeasonlzy/ImagePicker

@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);
    }
  }
});

代码示例来源:origin: robolectric/robolectric

@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());
}

代码示例来源:origin: MatthiasRobbers/shortbread

@Test
public void usesApplicationContext() {
  Shortbread.create(activity);
  verify(activity).getApplicationContext();
  verify(application).getSystemService(ShortcutManager.class);
}

相关文章

微信公众号

最新文章

更多

Activity类方法