7

Activity is getting restarted when system font is changed while app is running.

Is there any way I can avoid restarting of my Activity? I tested it with basic "Hello World" application.

I am using Android 4.1 as target

PS: I have tried using android:configChanges but there wasn't any flag related to font change.

TofferJ
  • 4,678
  • 1
  • 37
  • 49
sachy
  • 739
  • 7
  • 13

4 Answers4

1

U should use android:configChanges="fontScale" . but you would then need to handle that configuration change yourself by overriding onConfigurationChanged() Can refer this

user1969053
  • 1,750
  • 1
  • 12
  • 12
  • 1
    As i mentioned i already have tried this. But fontScale is for size of font and not the type – sachy Jan 16 '13 at 08:07
0

Take a look on official documentation : http://developer.android.com/guide/topics/manifest/activity-element.html#config

Look at "fontScale" maybe it will work.

Also you can just try to override onConfigurationChange function inside your activity to find out what changes.

EvZ
  • 11,889
  • 4
  • 38
  • 76
-1

You have to handle the configuration change by yourself.

android:configChanges="fontScale" works only for size of the font
Janmejoy
  • 2,721
  • 1
  • 20
  • 38
-1

I have tried the following, it should work for you, but it causes activity to destroy when font style has been changed then user has to launch the activity again

1) Have a global hashset to store the context strings when applcation starts put the context as string in this hashset

2) expose a method

isContextExits(contextStr) { return hashset.contains(contextStr); }

from application

3) Call ur activity by passing the content as string in the bundle.

onCreate(Bundle savedInstanceState)
mContextStr = savedInstanceState.getExtra("CONTEXT_STR");

// context has changed then finish the activity
if (!this.getApplicationContext().isContextStr(mContextStr))
  finish();

hope this helps !

Andrei Zhytkevich
  • 8,039
  • 2
  • 31
  • 45