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

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

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

Activity.getApplication介绍

暂无

代码示例

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

protected SetPasswordsAsyncTask(Activity activity, Account account,
                String incomingPassword, String outgoingPassword,
                List<Account> remainingAccounts) {
  super(activity);
  mAccount = account;
  mIncomingPassword = incomingPassword;
  mOutgoingPassword = outgoingPassword;
  mRemainingAccounts = remainingAccounts;
  mApplication = mActivity.getApplication();
}

代码示例来源:origin: google/agera

@Override
 public final void onActivityDestroyed(final Activity anyActivity) {
  if (activity == anyActivity) {
   activity.getApplication().unregisterActivityLifecycleCallbacks(this);
  }
 }
}

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

private void registerActivityListener(@NonNull Activity activity) {
  this.activity = activity;
  if (!hasRegisteredCallbacks) {
    hasRegisteredCallbacks = true;
    activity.getApplication().registerActivityLifecycleCallbacks(this);
    // Since Fragment transactions are async, we have to keep an <Activity, LifecycleHandler> map in addition
    // to trying to find the LifecycleHandler fragment in the Activity to handle the case of the developer
    // trying to immediately get > 1 router in the same Activity. See issue #299.
    activeLifecycleHandlers.put(activity, this);
  }
}

代码示例来源:origin: google/agera

/**
 * Builds the {@link RepositoryAdapter} that presents the provided repositories in order and
 * observes the repositories as well as any additional observables while the provided
 * {@link Activity} is resumed (between {@link Activity#onResume()} and
 * {@link Activity#onPause()}).
 * <p>
 * Note: Can only be called from {@link Activity#onCreate} ()}
 */
@TargetApi(14)
@NonNull
public Adapter<ViewHolder> whileResumed(@NonNull final Activity activity) {
 final RepositoryAdapter repositoryAdapter = new RepositoryAdapter(this);
 activity.getApplication().registerActivityLifecycleCallbacks(
   new WhileResumedActivityLifecycleCallbacks(activity, repositoryAdapter));
 return repositoryAdapter;
}

代码示例来源:origin: avjinder/Minimal-Todo

@Override
public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  addPreferencesFromResource(R.xml.preferences_layout);
  app = (AnalyticsApplication) getActivity().getApplication();
}

代码示例来源:origin: google/agera

/**
 * Builds the {@link RepositoryAdapter} that presents the provided repositories in order and
 * observes the repositories as well as any additional observables while the provided
 * {@link Activity} is started (between (between {@link Activity#onStart()} and
 * {@link Activity#onStop()}).
 * <p>
 * Note: Can only be called from {@link Activity#onCreate} ()}
 */
@TargetApi(14)
@NonNull
public Adapter<ViewHolder> whileStarted(@NonNull final Activity activity) {
 final RepositoryAdapter repositoryAdapter = new RepositoryAdapter(this);
 activity.getApplication().registerActivityLifecycleCallbacks(
   new WhileStartedActivityLifecycleCallbacks(activity, repositoryAdapter));
 return repositoryAdapter;
}

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

@Override
public void onDestroy() {
  super.onDestroy();
  if (activity != null) {
    activity.getApplication().unregisterActivityLifecycleCallbacks(this);
    activeLifecycleHandlers.remove(activity);
    destroyRouters();
    activity = null;
  }
}

代码示例来源:origin: seven332/EhViewer

@Override
  public boolean onPreferenceChange(Preference preference, Object newValue) {
    String key = preference.getKey();
    if (KEY_APP_LANGUAGE.equals(key)) {
      ((EhApplication) getActivity().getApplication()).recreate();
      return true;
    }
    return false;
  }
}

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

@Test
public void shouldReturnSameApplicationEveryTime() throws Exception {
 Activity activity = new Activity();
 assertThat(activity.getApplication()).isSameAs(activity.getApplication());
 assertThat(activity.getApplication()).isSameAs(new Activity().getApplication());
}

代码示例来源:origin: facebook/facebook-android-sdk

@Override
protected void onActivityResult(Intent data) {
  selectedPlace = ((ScrumptiousApplication) getActivity().getApplication())
      .getSelectedPlace();
  setPlaceText();
  notifyDataChanged();
}

代码示例来源:origin: facebook/facebook-android-sdk

@Override
protected void onActivityResult(Intent data) {
  selectedUsers = ((ScrumptiousApplication) getActivity().getApplication())
      .getSelectedUsers();
  setUsersText();
  notifyDataChanged();
}

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

@Override
public void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setHasOptionsMenu(true);
 setRetainInstance(true);
 App app=(App)getActivity().getApplication();
 Retrofit retrofit=
  new Retrofit.Builder()
   .baseUrl("https://api.stackexchange.com")
   .client(app.getOk())
   .addConverterFactory(GsonConverterFactory.create())
   .build();
 so=retrofit.create(StackOverflowInterface.class);
 picasso=
  new Picasso.Builder(getActivity())
   .downloader(new OkHttp3Downloader(app.getOk()))
   .build();
}

代码示例来源:origin: seven332/EhViewer

return true;
} else if (KEY_CLEAR_MEMORY_CACHE.equals(key)) {
  ((EhApplication) getActivity().getApplication()).clearMemoryCache();
  Runtime.getRuntime().gc();
} else if (KEY_EXPORT_DATA.equals(key)) {

代码示例来源:origin: seven332/EhViewer

@Override
  public boolean onPreferenceChange(Preference preference, Object newValue) {
    String key = preference.getKey();
    if (Settings.KEY_THEME.equals(key)) {
      ((EhApplication) getActivity().getApplication()).recreate();
      return true;
    } else if (Settings.KEY_APPLY_NAV_BAR_THEME_COLOR.equals(key)) {
      ((EhApplication) getActivity().getApplication()).recreate();
      return true;
    } else if (Settings.KEY_GALLERY_SITE.equals(key)) {
      getActivity().setResult(Activity.RESULT_OK);
      return true;
    } else if (Settings.KEY_LIST_MODE.equals(key)) {
      getActivity().setResult(Activity.RESULT_OK);
      return true;
    } else if (Settings.KEY_DETAIL_SIZE.equals(key)) {
      getActivity().setResult(Activity.RESULT_OK);
    } else if (Settings.KEY_THUMB_SIZE.equals(key)) {
      getActivity().setResult(Activity.RESULT_OK);
    } else if (Settings.KEY_SHOW_TAG_TRANSLATIONS.equals(key)) {
      if (Boolean.TRUE.equals(newValue)) {
        EhTagDatabase.update(getActivity());
      }
    }
    return true;
  }
}

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

@Test
public void shouldBeAContext() throws Exception {
 assertThat(Robolectric.setupActivity(Activity.class).getApplication())
   .isSameAs(ApplicationProvider.getApplicationContext());
 assertThat(Robolectric.setupActivity(Activity.class).getApplication().getApplicationContext())
   .isSameAs(ApplicationProvider.getApplicationContext());
}

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

if ((getActivityInfo(component.getApplication()).configChanges & changedBits) == changedBits) {
 shadowMainLooper.runPaused(() -> component.onConfigurationChanged(newConfiguration));

代码示例来源:origin: google/agera

@Before
public void setUp() {
 initMocks(this);
 updateDispatcher = updateDispatcher();
 repository = mutableRepository(REPOSITORY_ITEM);
 secondRepository = repository(REPOSITORY_LIST);
 when(activity.getApplication()).thenReturn(application);
 when(viewGroup.getContext()).thenReturn(context);
 when(context.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).thenReturn(layoutInflater);
 when(layoutInflater.inflate(LAYOUT_ID, viewGroup, false)).thenReturn(view);
 when(repositoryPresenter.getItemCount(REPOSITORY_ITEM)).thenReturn(1);
 when(secondRepositoryPresenter.getItemCount(REPOSITORY_LIST)).thenReturn(3);
 when(singleItemRepositoryPresenter.getItemCount(ITEM)).thenReturn(1);
 when(multiItemRepositoryPresenter.getItemCount(ITEM)).thenReturn(MULTI_ITEM_COUNT);
 when(zeroItemRepositoryPresenter.getItemCount(ITEM)).thenReturn(0);
 repositoryAdapter = repositoryAdapter()               // total | static | stable IDs assigned
   .add(repository, repositoryPresenter)             //     1 | 0      |
   .add(secondRepository, secondRepositoryPresenter) //     4 | 0      |
   .addLayout(layoutPresenter)                       //     5 | 1      | [@4] 0
   .addItem(ITEM, singleItemRepositoryPresenter)     //     6 | 2      | [@5] 1
   .addItem(ITEM, multiItemRepositoryPresenter)      //     9 | 5      | [@6-8] 2-4
   .addLayout(secondLayoutPresenter)                 //    10 | 6      | [@9] 5
   .addItem(ITEM, zeroItemRepositoryPresenter)       //    10 | 6      |
   .addAdditionalObservable(updateDispatcher)
   .build();
 repositoryAdapterWithoutStatic = repositoryAdapter()
   .add(repository, repositoryPresenter)
   .build();
}

代码示例来源:origin: palaima/DebugDrawer

@Override
  public void onActivityDestroyed(Activity activity) {
    this.activity.getApplication().unregisterActivityLifecycleCallbacks(this);
    this.activity = null;
    debugDrawer = null;
  }
}

代码示例来源:origin: syncthing/syncthing-android

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  ((SyncthingApp) getActivity().getApplication()).component().inject(this);
  ((SyncthingActivity) getActivity()).registerOnServiceConnectedListener(this);
}

代码示例来源:origin: grandcentrix/ThirtyInch

/**
 * registers the {@link #mActivityInstanceObserver}
 */
private ActivityInstanceObserver registerActivityObserver(final Activity activity) {
  if (mActivityInstanceObserver == null) {
    mActivityInstanceObserver = new ActivityInstanceObserver(this);
    TiLog.v(TAG, "registering lifecycle callback");
    activity.getApplication().registerActivityLifecycleCallbacks(mActivityInstanceObserver);
  }
  return mActivityInstanceObserver;
}

相关文章

Activity类方法