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(); }
@Override public final void onActivityDestroyed(final Activity anyActivity) { if (activity == anyActivity) { activity.getApplication().unregisterActivityLifecycleCallbacks(this); } } }
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); } }
/** * 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; }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences_layout); app = (AnalyticsApplication) getActivity().getApplication(); }
/** * 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; }
@Override public void onDestroy() { super.onDestroy(); if (activity != null) { activity.getApplication().unregisterActivityLifecycleCallbacks(this); activeLifecycleHandlers.remove(activity); destroyRouters(); activity = null; } }
@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; } }
@Test public void shouldReturnSameApplicationEveryTime() throws Exception { Activity activity = new Activity(); assertThat(activity.getApplication()).isSameAs(activity.getApplication()); assertThat(activity.getApplication()).isSameAs(new Activity().getApplication()); }
@Override protected void onActivityResult(Intent data) { selectedPlace = ((ScrumptiousApplication) getActivity().getApplication()) .getSelectedPlace(); setPlaceText(); notifyDataChanged(); }
@Override protected void onActivityResult(Intent data) { selectedUsers = ((ScrumptiousApplication) getActivity().getApplication()) .getSelectedUsers(); setUsersText(); notifyDataChanged(); }
@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(); }
return true; } else if (KEY_CLEAR_MEMORY_CACHE.equals(key)) { ((EhApplication) getActivity().getApplication()).clearMemoryCache(); Runtime.getRuntime().gc(); } else if (KEY_EXPORT_DATA.equals(key)) {
@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; } }
@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()); }
if ((getActivityInfo(component.getApplication()).configChanges & changedBits) == changedBits) { shadowMainLooper.runPaused(() -> component.onConfigurationChanged(newConfiguration));
@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(); }
@Override public void onActivityDestroyed(Activity activity) { this.activity.getApplication().unregisterActivityLifecycleCallbacks(this); this.activity = null; debugDrawer = null; } }
@Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); ((SyncthingApp) getActivity().getApplication()).component().inject(this); ((SyncthingActivity) getActivity()).registerOnServiceConnectedListener(this); }
/** * 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; }