Java Code Examples for android.app.Activity#recreate()

The following examples show how to use android.app.Activity#recreate() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Restarter.java    From freeline with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private static void restartActivity(Activity activity) {
    if (Log.isLoggable(LOG_TAG, Log.VERBOSE)) {
        Log.v(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(LOG_TAG, Log.VERBOSE)) {
            Log.v(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();
}
 
Example 2
Source File: TutorialFragment2.java    From BaldPhone with Apache License 2.0 5 votes vote down vote up
private void clickedEffect(TextView v) {
    longPressesFlag = (int) v.getTag();
    applyDuoToFlag();
    sharedPreferences.edit()
            .putBoolean(BPrefs.VIBRATION_FEEDBACK_KEY, longPressesFlag > 0)
            .putBoolean(BPrefs.LONG_PRESSES_KEY, longPressesFlag > 0)
            .putBoolean(BPrefs.LONG_PRESSES_SHORTER_KEY, longPressesFlag == 1)
            .putBoolean(BPrefs.TOUCH_NOT_HARD_KEY, longPressesFlag == 0)
            .apply();
    Activity activity = getActivity();
    if (activity != null) {
        activity.recreate();
    }

}
 
Example 3
Source File: LocalizedActivity.java    From ToGoZip with GNU General Public License v3.0 5 votes vote down vote up
/** force all open activity to recreate */
public static void recreate(Activity child) {
    Activity context = child;
    while (context != null) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            context.recreate();
        } else {
            // https://stackoverflow.com/questions/11495130/android-recreate-functions-in-api-7
            context.startActivity(new Intent(context, context.getClass()));
            context.finish();
        }
        context = context.getParent();
    }
}
 
Example 4
Source File: LifecycleListener.java    From sbt-android-protify with Apache License 2.0 5 votes vote down vote up
@Override
public void onActivityResumed(Activity activity) {
    top = activity;
    // should never be null
    long l = activities.get(activity);
    if (l < ProtifyApplication.getResourceInstallTime())
        activity.recreate();
}
 
Example 5
Source File: SettingTabFragment.java    From MusicPlayer with GNU General Public License v3.0 5 votes vote down vote up
@OnClick(R.id.switch_to_vi)
void switchToVI() {
    if(mIsEnglish) {
        Activity activity = getActivity();
        if (activity != null) {
            LocaleHelper.setLocale(activity, "vi");
            activity.recreate();
        }
    }

}
 
Example 6
Source File: CompatHelperBase.java    From edslite with GNU General Public License v2.0 5 votes vote down vote up
public static void restartActivity(Activity activity)
{
	if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
	    activity.recreate();
	else
	{
	    Intent intent = activity.getIntent();
	    activity.overridePendingTransition(0, 0);
	    intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
	    activity.finish();
	    activity.overridePendingTransition(0, 0);
	    activity.startActivity(intent);
	}
}
 
Example 7
Source File: ColorBox.java    From ColorBox-library with GNU General Public License v3.0 5 votes vote down vote up
public static void registerPreferenceUpdater(Activity activity) {

            if (isPreferenceChanged.containsKey(mTag) && sPreference && isPreferenceChanged.get(mTag)) {

                activity.recreate();
                sPreference = false;
            }
    }
 
Example 8
Source File: GlobalGUIRoutines.java    From PhoneProfilesPlus with Apache License 2.0 5 votes vote down vote up
static void reloadActivity(final Activity activity, @SuppressWarnings("SameParameterValue") boolean newIntent)
{
    if (activity == null)
        return;

    if (newIntent)
    {
        new Handler(activity.getMainLooper()).post(new Runnable() {

            @Override
            public void run() {
                try {
                    Context context = activity.getApplicationContext();

                    Intent intent = activity.getIntent();
                    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_ANIMATION);

                    activity.finish();
                    activity.overridePendingTransition(0, 0);

                    context.startActivity(intent);
                    //activity.overridePendingTransition(0, 0);
                } catch (Exception e) {
                    PPApplication.recordException(e);
                }
            }
        });
    }
    else
        activity.recreate();
}
 
Example 9
Source File: AppearancePreferenceFragment.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
  final Activity activity = getActivity();
  if (activity == null) return false;

  activity.recreate();

  if (TextSecurePreferences.LANGUAGE_PREF.equals(preference.getKey())) {
    Intent intent = new Intent(activity, KeyCachingService.class);
    intent.setAction(KeyCachingService.LOCALE_CHANGE_EVENT);
    activity.startService(intent);
  }

  return new ListSummaryListener().onPreferenceChange(preference, newValue);
}
 
Example 10
Source File: UIHelper.java    From coolreader with MIT License 5 votes vote down vote up
/**
 * Recreate the activity
 * 
 * @param activity
 *            target activity
 */
@SuppressLint("NewApi")
public static void Recreate(Activity activity) {
	if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
		activity.recreate();
	else {
		activity.finish();
		activity.startActivity(activity.getIntent());
	}
	CheckScreenRotation(activity);
	CheckKeepAwake(activity);
}
 
Example 11
Source File: ActivityUtils.java    From pybbsMD with Apache License 2.0 5 votes vote down vote up
public static void recreate(@NonNull Activity activity) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        activity.recreate();
    } else {
        Intent intent = activity.getIntent();
        intent.setClass(activity, activity.getClass());
        activity.startActivity(intent);
        activity.finish();
        activity.overridePendingTransition(0, 0);
    }
}
 
Example 12
Source File: Util.java    From NMSAlphabetAndroidApp with MIT License 4 votes vote down vote up
public static void restartActivity(Activity activity){
    if(activity != null) {
        activity.recreate();
    }
}
 
Example 13
Source File: ProtifyReceiver.java    From sbt-android-protify with Apache License 2.0 4 votes vote down vote up
@TargetApi(11)
private static void recreateActivity(Activity a) {
    if (a != null) a.recreate();
}
 
Example 14
Source File: CompatibilityImpl.java    From Overchan-Android with GNU General Public License v3.0 4 votes vote down vote up
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static void recreateActivity(Activity activity) {
    activity.recreate();
}
 
Example 15
Source File: SettingsActivity.java    From MaterialPreferenceLibrary with Apache License 2.0 4 votes vote down vote up
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static void restartActivity(final Activity activity) {
    activity.recreate();
}
 
Example 16
Source File: AppUtils.java    From materialistic with Apache License 2.0 4 votes vote down vote up
public static void restart(Activity activity, boolean transition) {
    activity.recreate();
}
 
Example 17
Source File: ThemeOverlayUtils.java    From material-components-android with Apache License 2.0 4 votes vote down vote up
public static void clearThemeOverlays(Activity activity) {
  themeOverlays.clear();
  activity.recreate();
}
 
Example 18
Source File: Themes.java    From android-app with GNU General Public License v3.0 4 votes vote down vote up
public static void checkTheme(Activity activity) {
    Theme appliedTheme = appliedThemes.get(activity);
    if(appliedTheme != theme) activity.recreate();
}
 
Example 19
Source File: MethodsCompat.java    From PreferenceFragment with Apache License 2.0 4 votes vote down vote up
@TargetApi(11)
public static void recreate(Activity activity) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        activity.recreate();
    }
}
 
Example 20
Source File: MethodsCompat.java    From wakao-app with MIT License 4 votes vote down vote up
@TargetApi(11)
public static void recreate(Activity activity) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        activity.recreate();
    }
}