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

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

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

Activity.recreate介绍

暂无

代码示例

代码示例来源:origin: hidroh/materialistic

public static void restart(Activity activity, boolean transition) {
  activity.recreate();
}

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

public void recreate() {
  // Copy list
  ArrayList<Activity> listCopy = new ArrayList<>(list.size());
  for (WeakReference<Activity> reference: list) {
   Activity activity = reference.get();
   if (activity == null) continue;
   listCopy.add(activity);
  }

  // Finish all activities
  for (int i = listCopy.size() - 1; i >= 0; --i) {
   listCopy.get(i).recreate();
  }
 }
}

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

@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
  PreferenceKeys preferenceKeys = new PreferenceKeys(getResources());
  if (key.equals(preferenceKeys.night_mode_pref_key)) {
    SharedPreferences themePreferences = getActivity().getSharedPreferences(MainFragment.THEME_PREFERENCES, Context.MODE_PRIVATE);
    SharedPreferences.Editor themeEditor = themePreferences.edit();
    //We tell our MainLayout to recreate itself because mode has changed
    themeEditor.putBoolean(MainFragment.RECREATE_ACTIVITY, true);
    CheckBoxPreference checkBoxPreference = (CheckBoxPreference) findPreference(preferenceKeys.night_mode_pref_key);
    if (checkBoxPreference.isChecked()) {
      //Comment out this line if not using Google Analytics
      app.send(this, "Settings", "Night Mode used");
      themeEditor.putString(MainFragment.THEME_SAVED, MainFragment.DARKTHEME);
    } else {
      themeEditor.putString(MainFragment.THEME_SAVED, MainFragment.LIGHTTHEME);
    }
    themeEditor.apply();
    getActivity().recreate();
  }
}

代码示例来源:origin: naman14/Timber

@Override
  public boolean onPreferenceChange(Preference preference, Object newValue) {
    // Marks both theme configs as changed so MainActivity restarts itself on return
    Config.markChanged(getActivity(), "light_theme");
    Config.markChanged(getActivity(), "dark_theme");
    // The dark_theme preference value gets saved by Android in the default PreferenceManager.
    // It's used in getATEKey() of both the Activities.
    getActivity().recreate();
    return true;
  }
});

代码示例来源:origin: TakWolf/CNode-Material-Design

@Override
public void run() {
  activity.recreate();
}

代码示例来源:origin: jrvansuita/MaterialAbout

@Override
  public void onClick(View view) {
    switch (view.getId()) {
      case R.id.dark:
        if (theme != R.style.AppThemeDark) {
          theme = R.style.AppThemeDark;
          activity.recreate();
        }
        break;
      case R.id.light:
        if (theme != R.style.AppThemeLight) {
          theme = R.style.AppThemeLight;
          activity.recreate();
        }
        break;

      case R.id.custom:
        if (theme != R.style.AppThemeCustom) {
          theme = R.style.AppThemeCustom;
          activity.recreate();
        }
        break;

      default:
        break;
    }
  }
}

代码示例来源:origin: michael-rapp/ChromeLikeTabSwitcher

@Override
public boolean onPreferenceChange(final Preference preference, final Object newValue) {
  getActivity().recreate();
  return true;
}

代码示例来源:origin: typ0520/fastdex

static void updateActivity(Activity activity) {
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
    if (Log.isLoggable(Logging.LOG_TAG, Log.VERBOSE)) {
      Log.v(Logging.LOG_TAG, "About to restart " + activity.getClass().getSimpleName());
    }
    // You can't restart activities that have parents: find the top-most activity
    while (activity.getParent() != null) {
      if (Log.isLoggable(Logging.LOG_TAG, Log.VERBOSE)) {
        Log.v(Logging.LOG_TAG, activity.getClass().getSimpleName()
            + " is not a top level activity; restarting "
            + activity.getParent().getClass().getSimpleName() + " instead");
      }
      activity = activity.getParent();
    }
    // Directly supported by the framework!
    activity.recreate();
  }
}

代码示例来源:origin: WangDaYeeeeee/Mysplash

public void dispatchRecreate() {
    for (Activity a : activityList) {
      a.recreate();
    }
  }
}

代码示例来源:origin: com.uphyca/android-junit4-robolectric

/**
 * 
 * @see android.app.Activity#recreate()
 */
public void recreate() {
  mActivity.recreate();
}

代码示例来源:origin: garretyoder/app-theme-engine

@Override
  public void run() {
    activity.recreate();
  }
});

代码示例来源:origin: fennifith/Status

@Override
  public void onDismiss(DialogInterface dialog) {
    if (isSettingsChanged)
      activity.recreate();
  }
}

代码示例来源:origin: bigsinger/fakegps

public void refreshAllActivity() {
  for (Activity activity : activityStack) {
    activity.recreate();
  }
}

代码示例来源:origin: stackoverflow.com

public void restartActivity(Activity activity){
  if (Build.VERSION.SDK_INT >= 11) {
    activity.recreate();
  } else {
    activity.finish();
    activity.startActivity(getIntent());
  }
}

代码示例来源:origin: DaylightingSociety/WhereAreTheEyes

public void onClick(DialogInterface dialog, int id) {
    dialog.dismiss();
    if (ContextCompat.checkSelfPermission(activity, Manifest.permission.ACCESS_FINE_LOCATION)
        == PackageManager.PERMISSION_GRANTED) {
      Log.d("REQUESTING PERMISSIONS", "We didn't have location permission, but the user fixed it!");
      activity.recreate();
    }
  }
});

代码示例来源:origin: WangDaYeeeeee/GeometricWeather

public void recreateAllActivities() {
    for (Activity a : activityList) {
      a.recreate();
    }
    for (Activity a : activityList) {
      Log.d("GeoApp", a.getClass().toString());
    }
  }
}

代码示例来源:origin: grzegorznittner/chanu

@Override
  public void onClick(DialogInterface dialog, int which) {
    pref.edit().putBoolean(SettingsActivity.PREF_SHOW_NSFW_BOARDS, true).commit();
    mActivity.recreate();
  }
});

代码示例来源:origin: grzegorznittner/chanu

@Override
  public void onClick(DialogInterface dialog, int which) {
    String newAutoloadValue = autoloadValues[which];
    pref.edit().putString(SettingsActivity.PREF_AUTOLOAD_IMAGES, newAutoloadValue).commit();
    dialog.dismiss();
    if (mActivity != null)
      mActivity.recreate();
  }
});

代码示例来源:origin: grzegorznittner/chanu

@Override
  public void onClick(DialogInterface dialog, int which) {
    String newAutoloadValue = values[which];
    pref.edit().putString(SettingsActivity.PREF_THEME, newAutoloadValue).commit();
    dialog.dismiss();
    if (mActivity != null)
      mActivity.recreate();
  }
});

代码示例来源:origin: fangx/ZhiHuMVP

public void notNight() {
  updateConfig(Configuration.UI_MODE_NIGHT_NO);
  System.gc();
  System.runFinalization(); // added in https://github.com/android/platform_frameworks_base/commit/6f3a38f3afd79ed6dddcef5c83cb442d6749e2ff
  System.gc();
  mActivity.get().recreate();
}

相关文章

微信公众号

最新文章

更多

Activity类方法