0

I have a Fragment that has a viewpager full of custom views.

When returning from my Settings Activity, the MainActivity gets the activity result and (if the language changed), calls recreate().

When debugging, I see the custom views going through onAttachedToWindow() and onDetachedToWindow() and finally ending at onAttachedToWindow(), but they never call onDraw(Canvas c) again, even if I call invalidate() on the view pager or the custom view itself, so the custom views are not showing up on the page.

I've also tried calling setRetainInstance(true); in the onCreateView for the Fragment.

What else should I try?

beyondtheteal
  • 729
  • 6
  • 15

1 Answers1

1

I had the same issue as you with an activity, the only way that I found was destroying and creating the activity again:

public void setLanguage(Context context, String languageToLoad) {

    Resources res = context.getResources();
    // Change locale settings in the app.
    DisplayMetrics dm = res.getDisplayMetrics();
    android.content.res.Configuration conf = res.getConfiguration();
    conf.locale = new Locale(languageToLoad.toLowerCase());
    res.updateConfiguration(conf, dm);
    Intent intent = new Intent(getApplicationContext(), MainMenuActivity.class);
    startActivity(intent);
    finish();

}

I know It's not the best way but I hope It help you.

I've found this:

if (Build.VERSION.SDK_INT >= 11) {
    recreate();
} else {
    Intent intent = getIntent();
    intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
    finish();
    overridePendingTransition(0, 0);

    startActivity(intent);
    overridePendingTransition(0, 0);
}

here How do I restart an Android Activity

Remember also to remove your fragment from the FragmentManager:

Fragment fragment = getSupportFragmentManager().findFragmentByTag(TAG_FRAGMENT);
if(fragment != null)
    getSupportFragmentManager().beginTransaction().remove(fragment).commit();
Community
  • 1
  • 1
Miguel Benitez
  • 2,322
  • 10
  • 22