[Android] In-app language changing library

Overview

Android Arsenal Maven Central Minimum SDK Version Workflow Status

Localization Library

Header image Android library for in-app language changes support in your application

Feature

  • In-app language changing
  • Default language when first launch
  • Work with string resource in XML and programmatically
  • RTL language support
  • Align on platform behavior

Demo

Try it at Google Play

Download

Since version 1.2.9 will move from JCenter to MavenCentral

// build.gradle (project)
allprojects {
    repositories {
        mavenCentral()
        /* ... */
    }
}

Gradle

implementation 'com.akexorcist:localization:1.2.10'

(Optional) You can exclude androidx.appcompat:appcompat, if your project does not use AppCompat.

implementation ('com.akexorcist:localization:1.2.10') {
    exclude group: 'androidx.core', module: 'core'
}

Usage

Custom application class which extends from LocalizationApplication is require.

class MainApplication: LocalizationApplication() {
    /* ... */
    override fun getDefaultLanguage() = Locale.ENGLISH
}

Either not, using LocalizationApplicationDelegate with additional code as below

class MainApplication: Application() {
    private val localizationDelegate = LocalizationApplicationDelegate()
    
    override fun attachBaseContext(base: Context) {
        localizationDelegate.setDefaultLanguage(base, Locale.ENGLISH)
        super.attachBaseContext(localizationDelegate.attachBaseContext(base))
    }
    
    override fun onConfigurationChanged(newConfig: Configuration) {
        super.onConfigurationChanged(newConfig)
        localizationDelegate.onConfigurationChanged(this)
    }
    
    override fun getApplicationContext(): Context {
        return localizationDelegate.getApplicationContext(super.getApplicationContext())
    }
    
    override fun getResources(): Resources {
        return localizationDelegate.getResources(baseContext, super.getResources())
    }
}

For the activities, extends from LocalizationActivity.

class MainActivity: LocalizationActivity() {
    /* ... */
}

Or using LocalizationActivityDelegate with additional code

open class CustomActivity : Activity(), OnLocaleChangedListener {
    private val localizationDelegate = LocalizationActivityDelegate(this)

    public override fun onCreate(savedInstanceState: Bundle?) {
        localizationDelegate.addOnLocaleChangedListener(this)
        localizationDelegate.onCreate()
        super.onCreate(savedInstanceState)
    }

    public override fun onResume() {
        super.onResume()
        localizationDelegate.onResume(this)
    }

    override fun attachBaseContext(newBase: Context) {
        applyOverrideConfiguration(localizationDelegate.updateConfigurationLocale(newBase))
        super.attachBaseContext(newBase)
    }

    override fun getApplicationContext(): Context {
        return localizationDelegate.getApplicationContext(super.getApplicationContext())
    }

    override fun getResources(): Resources {
        return localizationDelegate.getResources(super.getResources())
    }

    fun setLanguage(language: String?) {
        localizationDelegate.setLanguage(this, language!!)
    }

    fun setLanguage(locale: Locale?) {
        localizationDelegate.setLanguage(this, locale!!)
    }

    val currentLanguage: Locale
        get() = localizationDelegate.getLanguage(this)

    // Just override method locale change event
    override fun onBeforeLocaleChanged() {}
    override fun onAfterLocaleChanged() {}
}

Then prepare your multilingual content in string resource.

Multilingual Content

Public method on LocalizationActivity

It have only 4 public methods.

fun setLanguage(language: String)
fun setLanguage(language: String, country: Strinng)
fun setLanguage(locale: Locale)
fun getCurrentLanguage(): String

setLanguage Set the language that you need to change.

For example

setLanguage("th")                             // Language : Thailand
setLanguage("th", "TH")                       // Language : Thailand, Country : Thai
setLanguage(Locale("th", "TH"))               // Language : Thailand, Country : Thai
setLanguage("en")                             // Language : English
setLanguage("en", "GB")                       // Language : English,  Country : Great Britain
setLanguage("en", "US")                       // Language : English,  Country : United States
setLanguage(Locale("en", "US"))               // Language : English,  Country : United States
setLanguage(Locale.KOREA)                     // Language : Korean,   Country : Korea
setLanguage(Locale.KOREAN)                    // Language : Korean
setLanguage(Locale.CANADA_FRENCH)             // Language : French,   Country : Canada

getLanguage Get current language as string locale.

And 2 optional override methods.

fun onBeforeLocaleChanged()
fun onAfterLocaleChanged()

This override method will be useful when you need to know when language has changed.

Back Stack 1

When setLanguage was called. Current active activity will be recreated to apply the new language.

Back Stack 2

Previous activities in back stack does not change to new language immediately. Until it back to active activity again.

Back Stack 3

Back Stack 4

Back Stack 5

Action Bar or Toolbar's title

You have to call setTitle(resId) or getActionBar().setTitle(resId) in onCreate(onSavedInstanceState: Bundle) to apply the new language.

class MainActivity: LocalizationActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        /* ... */
        setTitle(R.string.main_activity_title)
    }
}

Handle state changes

Activity will be recreate when language has changed as common behavior for configuration changes in Android. Any Activities or Fragments which hold the data should handle the state changes.

Change the language in Fragment

Language in fragment will depends on activity. So no need for additional code in Fragment.

Service

For normally usage, just extends from LocalizationService

class SimpleService : LocalizationService() {
    /* ... */
}

Or using LocalizationServiceDelegate with additional code

abstract class CustomService : Service() {
    private val localizationDelegate: LocalizationServiceDelegate by lazy {
        LocalizationServiceDelegate(this)
    }

    override fun getBaseContext(): Context {
        return localizationDelegate.getBaseContext(super.getBaseContext())
    }

    override fun getApplicationContext(): Context {
        return localizationDelegate.getApplicationContext(super.getApplicationContext())
    }

    override fun getResources(): Resources {
        return localizationDelegate.getResources(super.getResources())
    }
}

BroadcastReceiver

BroadcastReceiver is abstract class. So we cannot create LocalizationBroadcastReceiver fot you.

In this case, you need to convert the context in onReceive(context: Context, intent: Intent) to localized context with Context.toLocalizedContext() before using.

class SimpleBroadcastReceiver : BroadcastReceiver() {
    override fun onReceive(context: Context, intent: Intent) {
        val localizedContext = context.toLocalizedContext()
        /* ... */
    }
}

Language resources optimization in Android App Bundle

Change the language by library can cause a crash to your app when you publishing your app with Android App Bundle with language resources optimization enabled.

To fix this, Using the Additional Languages API in Play Core library to download the additional language before.

For more information about Additional Language API : https://android-developers.googleblog.com/2019/03/the-latest-android-app-bundle-updates.html

If you don't want to implement this feature in your code, just ignore the language resources optimization by adding the Android App Bundle configuration in your app's build.gradle

android {
    /* ... */ 
    bundle { 
        language { 
            enableSplit = false 
        } 
    } 
}

ProGuard

Normally, there's no require the ProGuard rules for this library.

But if you want to exclude this library from obfuscate and shrinking. You also can add these code to proguard-rules.pro

-keep class com.akexorcist.localizationactivity.** { *; }
-dontwarn com.akexorcist.localizationactivity.**

Change Log

See CHANGELOG.md

Licence

Copyright 2021 Akexorcist

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this work except in compliance with the License. You may obtain a copy of the License in the LICENSE file, or at:

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Comments
  • Caused by java.lang.UnsupportedOperationException Failed to resolve attribute at index 6: TypedValue{t=0x2/d=0x101009b a=1}

    Caused by java.lang.UnsupportedOperationException Failed to resolve attribute at index 6: TypedValue{t=0x2/d=0x101009b a=1}

    I'm using 1.2.7 version override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { return inflater.inflate(getResId(), container, false) <<<< error line }

    An error occurs when creating a customAlertDialogFragment. I guess the theme was influenced.

    It doesn't happen if I downgrade to 1.2.6 version.

    opened by kyh8496 15
  •  java.lang.UnsupportedOperationException: Failed to resolve attribute at index 37: TypedValue{t=0x2/d=0x7f04024a a=-1}

    java.lang.UnsupportedOperationException: Failed to resolve attribute at index 37: TypedValue{t=0x2/d=0x7f04024a a=-1}

    Device Qos (some samsung devices). Issue cause when you using androidx.appcompat.app.AlertDialog Hope you can fix it soon. Thank you [Plus at this time for any one face the same issue like me. Please override
    @style/MyDialogTheme to your app theme. It will work. ]

    layout/select_dialog_singlechoice_material: Error inflating class CheckedTextView Caused by: android.view.InflateException: Binary XML file line #18 in com.vietbm.computerlauncher:layout/select_dialog_singlechoice_material: Error inflating class CheckedTextView Caused by: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 37: TypedValue{t=0x2/d=0x7f04024a a=-1} at android.content.res.TypedArray.getDimensionPixelSize(TypedArray.java:782) at android.view.View.(View.java:6222) at android.widget.TextView.(TextView.java:1247) at android.widget.CheckedTextView.(CheckedTextView.java:102) at android.widget.CheckedTextView.(CheckedTextView.java:98) at androidx.appcompat.widget.AppCompatCheckedTextView.(AppCompatCheckedTextView.java:58) at androidx.appcompat.widget.AppCompatCheckedTextView.(AppCompatCheckedTextView.java:53) at androidx.appcompat.app.AppCompatViewInflater.createCheckedTextView(AppCompatViewInflater.java:234) at androidx.appcompat.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:147) at androidx.appcompat.app.AppCompatDelegateImpl.createView(AppCompatDelegateImpl.java:1551) at androidx.appcompat.app.AppCompatDelegateImpl.onCreateView(AppCompatDelegateImpl.java:1602) at android.view.LayoutInflater.tryCreateView(LayoutInflater.java:1059) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:995) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:959) at android.view.LayoutInflater.inflate(LayoutInflater.java:657) at android.view.LayoutInflater.inflate(LayoutInflater.java:532) at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:425) at android.widget.ArrayAdapter.getView(ArrayAdapter.java:416) at android.widget.AbsListView.obtainView(AbsListView.java:2629) at android.widget.ListView.measureHeightOfChildren(ListView.java:1452) at android.widget.ListView.onMeasure(ListView.java:1358) at android.view.View.measure(View.java:27131) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:7951) at android.widget.FrameLayout.onMeasure(FrameLayout.java:194) at android.view.View.measure(View.java:27131) at androidx.appcompat.widget.AlertDialogLayout.tryOnMeasure(AlertDialogLayout.java:134) at androidx.appcompat.widget.AlertDialogLayout.onMeasure(AlertDialogLayout.java:64) at android.view.View.measure(View.java:27131) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:7951) at android.widget.FrameLayout.onMeasure(FrameLayout.java:194) at androidx.appcompat.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:146) at android.view.View.measure(View.java:27131) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:7951) at android.widget.FrameLayout.onMeasure(FrameLayout.java:194) at android.view.View.measure(View.java:27131) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:7951) at android.widget.FrameLayout.onMeasure(FrameLayout.java:194) at android.view.View.measure(View.java:27131) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:7951) at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1552) at android.widget.LinearLayout.measureVertical(LinearLayout.java:842) at android.widget.LinearLayout.onMeasure(LinearLayout.java:721) at android.view.View.measure(View.java:27131) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:7951) at android.widget.FrameLayout.onMeasure(FrameLayout.java:194) at com.android.internal.policy.DecorView.onMeasure(DecorView.java:1173) at android.view.View.measure(View.java:27131) at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:4187)

    opened by Stupidman22 8
  • Selected language is ignored after app restart on AppCompat 1.3.0-alpha01

    Selected language is ignored after app restart on AppCompat 1.3.0-alpha01

    Bug: App starts with default / phone language A, I change the language to B, force close the app from recent apps, open the app again, app's language is back to A. Language is retained if the app is minimized and restored.

    I had this issue for a while in my app, but couldn't figure out why. Today I noticed the same behavior on my other app while I was upgrading dependencies. Confirmed the bug in the sample app by changing AppCompat version to 1.3.0-alpha01. The bug is not present in both 1.1.0 and 1.2.0-alpha01.

    opened by alashow 8
  • After using version 1.2.6 application crashes for release version while opening. For debug it works fine.

    After using version 1.2.6 application crashes for release version while opening. For debug it works fine.

    java.lang.NoClassDefFoundError: Failed resolution of: LZM; at com.akexorcist.localizationactivity.core.LanguageSetting.setDefaultLanguage(Unknown Source:2)

    I am using APK for generation and not the APP bundle.

    opened by sushantp777 7
  • Dark theme support

    Dark theme support

    I use Application to setting my app as README saying. But when the System Theme has changed to dark/light theme, my app will not auto change theme. If I do not set Application and just use LocalizationApplication, my app won't go wrong.

    enhancement 
    opened by xz-dev 6
  • App is crashing in LocalizationApplication getApplicationContext()

    App is crashing in LocalizationApplication getApplicationContext()

    Hi found below issue in some devices, can you please help me to get it resolve. I have mentioned error below

    Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.Context android.content.Context.getApplicationContext()' on a null object reference at android.content.ContextWrapper.getApplicationContext(ContextWrapper.java:118) at com.LocalizationApplication.getApplicationContext(LocalizationApplication.java:23)

    opened by ashutoshgohil 5
  • java.lang.NoSuchMethodException:

    java.lang.NoSuchMethodException:

    Sometimes i get this error...i was using 1.2.4 version

    java.lang.RuntimeException: at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:3308) at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:3457) at android.app.servertransaction.LaunchActivityItem.execute (LaunchActivityItem.java:83) at android.app.servertransaction.TransactionExecutor.executeCallbacks (TransactionExecutor.java:135) at android.app.servertransaction.TransactionExecutor.execute (TransactionExecutor.java:95) at android.app.ActivityThread$H.handleMessage (ActivityThread.java:2044) at android.os.Handler.dispatchMessage (Handler.java:107) at android.os.Looper.loop (Looper.java:223) at android.app.ActivityThread.main (ActivityThread.java:7562) at java.lang.reflect.Method.invoke (Method.java) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:539) at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:950) Caused by: androidx.fragment.app.Fragment$InstantiationException: at androidx.fragment.app.Fragment.instantiate (Fragment.java:3) at androidx.fragment.app.FragmentContainer.instantiate (FragmentContainer.java:3) at androidx.fragment.app.FragmentManager$3.instantiate (FragmentManager.java:3) at androidx.fragment.app.FragmentStateManager. (FragmentStateManager.java:10) at androidx.fragment.app.FragmentManager.restoreSaveState (FragmentManager.java:6) at androidx.fragment.app.FragmentController.restoreSaveState (FragmentController.java:3) at androidx.fragment.app.FragmentActivity.onCreate (FragmentActivity.java:3) at androidx.appcompat.app.AppCompatActivity.onCreate (AppCompatActivity.java:10) at com.akexorcist.localizationactivity.ui.LocalizationActivity.onCreate (LocalizationActivity.java:5) at com.example.MapActivity.onCreate (MapActivity.java:5) at android.app.Activity.performCreate (Activity.java:7893) at android.app.Activity.performCreate (Activity.java:7880) at android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1307) at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:3283) at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:3457) at android.app.servertransaction.LaunchActivityItem.execute (LaunchActivityItem.java:83) at android.app.servertransaction.TransactionExecutor.executeCallbacks (TransactionExecutor.java:135) at android.app.servertransaction.TransactionExecutor.execute (TransactionExecutor.java:95) at android.app.ActivityThread$H.handleMessage (ActivityThread.java:2044) at android.os.Handler.dispatchMessage (Handler.java:107) at android.os.Looper.loop (Looper.java:223) at android.app.ActivityThread.main (ActivityThread.java:7562) at java.lang.reflect.Method.invoke (Method.java) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:539) at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:950) Caused by: java.lang.NoSuchMethodException: at java.lang.Class.getConstructor0 (Class.java:2332) at java.lang.Class.getConstructor (Class.java:1728) at androidx.fragment.app.Fragment.instantiate (Fragment.java:3) at androidx.fragment.app.FragmentContainer.instantiate (FragmentContainer.java:3) at androidx.fragment.app.FragmentManager$3.instantiate (FragmentManager.java:3) at androidx.fragment.app.FragmentStateManager. (FragmentStateManager.java:10) at androidx.fragment.app.FragmentManager.restoreSaveState (FragmentManager.java:6) at androidx.fragment.app.FragmentController.restoreSaveState (FragmentController.java:3) at androidx.fragment.app.FragmentActivity.onCreate (FragmentActivity.java:3) at androidx.appcompat.app.AppCompatActivity.onCreate (AppCompatActivity.java:10) at com.akexorcist.localizationactivity.ui.LocalizationActivity.onCreate (LocalizationActivity.java:5) at com.example.MapActivity.onCreate (MapActivity.java:5) at android.app.Activity.performCreate (Activity.java:7893) at android.app.Activity.performCreate (Activity.java:7880) at android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1307) at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:3283) at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:3457) at android.app.servertransaction.LaunchActivityItem.execute (LaunchActivityItem.java:83) at android.app.servertransaction.TransactionExecutor.executeCallbacks (TransactionExecutor.java:135) at android.app.servertransaction.TransactionExecutor.execute (TransactionExecutor.java:95) at android.app.ActivityThread$H.handleMessage (ActivityThread.java:2044) at android.os.Handler.dispatchMessage (Handler.java:107) at android.os.Looper.loop (Looper.java:223) at android.app.ActivityThread.main (ActivityThread.java:7562) at java.lang.reflect.Method.invoke (Method.java) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:539) at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:950)

    opened by filipstojakovic 5
  • ClassCastException: LocalizationContext cannot be cast to android.app.ContextImpl on API 16

    ClassCastException: LocalizationContext cannot be cast to android.app.ContextImpl on API 16

    Hi! On android API 16 I get such exception (and crash):

    java.lang.RuntimeException: Unable to start receiver com.xxx.InactivityHandler: java.lang.ClassCastException: com.akexorcist.localizationactivity.core.LocalizationContext cannot be cast to android.app.ContextImpl
            at android.app.ActivityThread.handleReceiver(ActivityThread.java:2236)
            at android.app.ActivityThread.access$1500(ActivityThread.java:130)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1271)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:4745)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
            at dalvik.system.NativeStart.main(Native Method)
         Caused by: java.lang.ClassCastException: com.akexorcist.localizationactivity.core.LocalizationContext cannot be cast to android.app.ContextImpl
            at android.app.ActivityThread.handleReceiver(ActivityThread.java:2226)
            at android.app.ActivityThread.access$1500(ActivityThread.java:130) 
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1271) 
            at android.os.Handler.dispatchMessage(Handler.java:99) 
            at android.os.Looper.loop(Looper.java:137) 
            at android.app.ActivityThread.main(ActivityThread.java:4745) 
            at java.lang.reflect.Method.invokeNative(Native Method) 
            at java.lang.reflect.Method.invoke(Method.java:511) 
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) 
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 
            at dalvik.system.NativeStart.main(Native Method)
    

    InactivityHandler is defined in AndroidManifest as

    bug 
    opened by varrav 5
  • Not working for new AndroidX appcompat versions

    Not working for new AndroidX appcompat versions

    Recently I upgraded my AndroidX dependency versions (from 1.1.0 to 1.2.0-beta01) and some users started reporting that the app's locale changing feature stopped working. I was using the 1.2.2 version at the time now I changed upgraded it 1.2.4 but it didn't fix it.

    It was working fine on my Pixel 3 XL and Android emulator (different Android versions) but I've seen at least 2 complaints in reviews. So after some digging, I was finally able to reproduce it by using appetize.io emulator. I reverted AndroidX version back to 1.1.0 and it worked properly as before (diff).

    When it's not working, it uses the system language. It changes only when the system language changes.

    Any ideas on what might be wrong?

    bug 
    opened by alashow 5
  • Fix compatibility with Hilt ViewModel injection

    Fix compatibility with Hilt ViewModel injection

    • Adds compatibility with hilt's ViewModel injection
    • a bit of code cleanup

    Will close https://github.com/akexorcist/Localization/issues/96 and probably:

    1. https://github.com/akexorcist/Localization/issues/95
    2. https://github.com/akexorcist/Localization/issues/94
    3. https://github.com/akexorcist/Localization/issues/63
    opened by LloydBlv 4
  • Not work when switching system dark theme using compose isSystemInDarkTheme().

    Not work when switching system dark theme using compose isSystemInDarkTheme().

    As title and I use below :

    • LocalizationActivity
    • LocalizationApplication

    Can change language, but cannot switch dark theme (compose's isSystemInDarkTheme()).

    enhancement 
    opened by ccmtmp 4
  • Crash on checkLocaleChange

    Crash on checkLocaleChange

    Because of the lateinit var, currentLanguage can be used before its initialization :

    2022-04-26 11:54:34.654 4223-4223/com.tabesto.myapp E/AndroidRuntime: FATAL EXCEPTION: main
        Process: com.tabesto.myapp, PID: 4223
        kotlin.UninitializedPropertyAccessException: lateinit property currentLanguage has not been initialized
            at com.akexorcist.localizationactivity.core.LocalizationActivityDelegate.checkLocaleChange(LocalizationActivityDelegate.kt:175)
            at com.akexorcist.localizationactivity.core.LocalizationActivityDelegate.access$checkLocaleChange(LocalizationActivityDelegate.kt:12)
            at com.akexorcist.localizationactivity.core.LocalizationActivityDelegate$onResume$1.run(LocalizationActivityDelegate.kt:37)
            at android.os.Handler.handleCallback(Handler.java:938)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:246)
            at android.app.ActivityThread.main(ActivityThread.java:8653)
            at java.lang.reflect.Method.invoke(Native Method)
            at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)
    

    You can facing this issue by using Direct-Boot : with this, we cannot initialize language before first onResume() call.

    I've submited a PR to fix this : https://github.com/akexorcist/Localization/pull/135

    opened by julienherrero 1
  • Theme change not working

    Theme change not working

    Steps to reproduce

    1. Set application theme with AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM).
    2. Use the system setting (Settings -> Display -> Theme) to toggle Dark theme.

    Expected

    The application theme should also be changed automatically in accordance with device theme.

    opened by RkNaing 1
  • Version 1.2.10 => Caused by android.os.BadParcelableException: ClassNotFoundException when unmarshalling: cf

    Version 1.2.10 => Caused by android.os.BadParcelableException: ClassNotFoundException when unmarshalling: cf

    I'm using the 1.2.10 version of Localization Library. Please check below logs of crashlytics for more details.

    Fatal Exception: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.tutorialdemo/com.activity.MainActivity}: android.os.BadParcelableException: ClassNotFoundException when unmarshalling: cf at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3175) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3312) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:113) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:71) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2038) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:226) at android.app.ActivityThread.main(ActivityThread.java:7178) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:503) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:942)

    Caused by android.os.BadParcelableException: ClassNotFoundException when unmarshalling: cf at android.os.Parcel.readParcelableCreator(Parcel.java:2855) at android.os.Parcel.readParcelable(Parcel.java:2781) at android.os.Parcel.readValue(Parcel.java:2684) at android.os.Parcel.readArrayMapInternal(Parcel.java:3053) at android.os.BaseBundle.initializeFromParcelLocked(BaseBundle.java:288) at android.os.BaseBundle.unparcel(BaseBundle.java:232) at android.os.Bundle.getParcelable(Bundle.java:940) at androidx.fragment.app.FragmentActivity$2.onContextAvailable(FragmentActivity.java:148) at androidx.activity.contextaware.ContextAwareHelper.dispatchOnContextAvailable(ContextAwareHelper.java:99) at androidx.activity.ComponentActivity.onCreate(ComponentActivity.java:322) at androidx.fragment.app.FragmentActivity.onCreate(FragmentActivity.java:273) at com.akexorcist.localizationactivity.ui.LocalizationActivity.onCreate(LocalizationActivity.kt:24) at com.activity.MainActivity.onCreate(MainActivity.java:192) at android.app.Activity.performCreate(Activity.java:7383) at android.app.Activity.performCreate(Activity.java:7374) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3155) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3312) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:113) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:71) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2038) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:226) at android.app.ActivityThread.main(ActivityThread.java:7178) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:503) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:942)

    opened by AxitaKathiriya 11
  • java.lang.RuntimeException: Using WebView from more than one process at once

    java.lang.RuntimeException: Using WebView from more than one process at once

    Hey there. My app's bug reporting tool is reporting several crashes around the use of WebView in LocalizationApplicationDelegate.

    Unable to create application [application.name]: java.lang.RuntimeException: Using WebView from more than one process at once with the same data directory is not supported. https://crbug.com/558377 : Current process [process name] (pid 20098), lock owner [process name] (pid 21177)
    

    I'm unfortunately not sure how to reproduce this crash. My best guess is that my application is trying to instantiate a WebView on startup with the same process name as another instance of my app that is in the process of getting killed.

    opened by ryandt 3
Releases(1.2.11)
  • 1.2.11(Dec 21, 2021)

    • [Bug] Bug fixed #105 #118 #114 #118
    • [PR] #125 - Fix WebView crashing on Android 5
    • Update Gradle and dependencies version
      • Compile SDK Version 31
      • Target SDK Version 31
      • Kotlin : 1.6.10
      • Gradle : 7.0.2
      • Gradle Plugin : 4.2.2
      • Activity KTX : 1.4.0
      • AndroidX AppCompat 1.4.0
    Source code(tar.gz)
    Source code(zip)
  • 1.2.10(Dec 21, 2021)

    • [Bug] Bug fixed #105 #103 #92
    • [PR] #108 - Fix resource not found crash
    • Fix incorrect Configuration creation
    • Using centralize localized logic (See LocalizationUtility)
    • Remove LocalizationContext (no need anymore)
    • Prevent BadParcelableException in LocalizationActivityDelegate.checkBeforeLocaleChanging() with try-catch
    • Change LocalizationDelegate.getResources(Context) to LocalizationDelegate.getResources(Context, Resources) because resources from super class is require in this method. That's mean who does not using LocalizationApplication must update this method
    Source code(tar.gz)
    Source code(zip)
  • 1.2.9(Apr 13, 2021)

    • [Bug] Bug fixed #93 #95
    • [PR] #101 - Update README.md
    • Add LocalizationService and LocalizationServiceDelegate for Service
    • Add Context.toLocalizedContext() extension function to convert context to localized context
    • Add more sample code and UI test for Dialog Fragment, Dialog + WebView, and BroadcastReceiver
    • Update Gradle and dependencies version
      • Kotlin : 1.4.32
      • Gradle Plugin : 4.1.3
      • Activity KTX : 1.2.2
    Source code(tar.gz)
    Source code(zip)
  • 1.2.8(Apr 5, 2021)

  • 1.2.7(Mar 6, 2021)

    • [PR] #74 - Add setLanguageWithoutNotification
    • [PR] #83 - fix: activity Intent can be NULL
    • [Bug] Bug fixed #72 #75
    • Migrate sample project from Java to Kotlin
    • New UI for sample project
    • Add more sample code for Dark Theme and Hilt Dependency Injection
    • Migrate UI test from Espresso to Kakao
    • Update Gradle and dependencies version
      • Kotlin : 1.4.31
      • Gradle Plugin : 4.1.2
      • Gradle Wrapper : 6.5
    Source code(tar.gz)
    Source code(zip)
  • 1.2.6(Aug 31, 2020)

    • [PR] #66 - Fix incompatible with AppCompat 1.2.0 or higher
    • [PR] #60 - Supporting locale variants
    • Bug fixed #65
    • Add layout resource support in LocalizationActivity's constructor
    • Fix base context and application context not update in some version
    • Update UI test
    • Update Gradle and dependencies version
      • Kotlin : 1.3.72
      • Gradle Plugin : 4.0.1
      • Gradle Wrapper : 6.1.1
      • AppCompat : 1.2.0
    Source code(tar.gz)
    Source code(zip)
  • 1.2.5(Apr 15, 2020)

    • Bug fixed #53 #52 #41
    • Removed dummy activity for fade in/out transition when language changing (if you want, create by yourself when onBeforeLocaleChanged(...) called)
    • API level 14 supported (#54)
    • Added example code for AndroidX Preferences
    Source code(tar.gz)
    Source code(zip)
  • 1.2.4(Jan 4, 2020)

  • 1.2.3(Jan 1, 2020)

    • Bug fixed : Incorrect behavior in API level 24-27 (Android 7.0 - 8.1) #30 #37
    • Bug fixed : setDefaultLanguage does not work properly #28
    • Migrate to AndroidX and latest Gradle
    • Migrate to Kotlin
    • Add UI automated test in example code
    • Move set default language to Application class (Please see the migrate instruction)
    • Add pre-implemented application class for LocalizationApplicationDelegate
    Source code(tar.gz)
    Source code(zip)
  • 1.2.2(Oct 31, 2017)

  • 1.2.1(Oct 19, 2017)

    Support string resource from getApplicationContext() Add LocalizationApplicationDelegate. So you need to custom application class in your app LocalizationDelegate was deprecated, replace by LocalizationActivityDelegate

    Source code(tar.gz)
    Source code(zip)
  • 1.2.0(Oct 15, 2017)

  • 1.1.2(Oct 11, 2017)

  • 1.1.1(Jun 22, 2016)

  • 1.1.0(Jun 22, 2016)

    Custom your own activity to supported language changing without extends from AppCompatActivity. Update build tools and gradle plugin version

    Source code(tar.gz)
    Source code(zip)
  • 1.0.9(Oct 16, 2015)

Owner
Akexorcist
Lovely android developer who enjoys learning in android technology, habitual article writer about Android development for Android developers in Thailand
Akexorcist
A showcase music app for Android entirely written using Kotlin language

Bandhook Kotlin This project is a small replica of the app I developed some time ago. Bandhook can still be found on Play Store At the moment it will

Antonio Leiva 1.9k Dec 23, 2022
📰👓Android App that fetches fresh news based on your language and location

News App that fetches fresh news based on your language and location. You can share and browse news in one click! How to install You can open it with

Valeria 1 Feb 21, 2022
An android app written in Kotlin Programming language which a user can use to store his/her monthly expenditure.

#Expenditure-Tracker An android app that allows the user to input , edit , view his/her expenditures for each month. Languages Used - Kotlin UI develo

Priyansh Agarwal 2 Aug 21, 2022
Smart-flight - This app was created to learn and practice Kotlin language

Smart Flight This app was created to learn and practice Kotlin language. Works o

Kamil 1 Feb 9, 2022
Modern-android-lab - Kotlin Language learning lab

kotlin-code-labs Kotlin Language learning lab Run the code with Kotlin Compiler:

Samuel Owino 4 Nov 7, 2022
It is a project that contains lessons and examples about Kotlin programming language. 🇰

Kotlin Tutorials What is Kotlin? I added the platforms it supports and great resources. You can access the article from the link below: https://medium

Halil Özel 94 Dec 22, 2022
A multi-modular Gradle project that encapsulates various modules to learn Kotlin language, tools and frameworks.

KotlinLearn This is a gradle project for the sole basis of exploring and learning Kotlin language, tools and frameworks. The root project wil encapsul

Victor Kiprop 2 Oct 10, 2021
Solutions to advent of code 2021 in the gen-Z programming language known as kotlin

Advent Of Code 2021 - Kotlin Edition How to run? Get the kotlin SDK using the sdkman tool: https://sdkman.io/sdks#kotlin Run the commands: ./gradlew

Arijan 2 Jan 7, 2022
Calculator - A Simple Calculator Application Using Kotlin Language

Calculator A Simple Calculator Application Using Kotlin Language Some Screenshot

Shounak Das 3 Oct 17, 2022
Some sort of a language'ish thing to be.

MarkSLang MarkSLang Ⓒ 2022 Markku Sukanen. Some sort of language(ish) thing to be. Features Simple calculations, loops, conditional(s), etc. Simple RE

Markku Sukanen 1 Jun 17, 2022
The domain specific programming language D°, which is a result of Fabian Bruckner's PhD.

Data App Programming Language The data app programming language (named D° [spoken dəˈɡrē]) is a work result of the PhD of Fabian Bruckner. It is a dom

Fraunhofer Institute for Software and Systems Engineering ISST 2 Aug 19, 2022
PNPscript - ProdigyPNP's upcoming programming language, designed for hacking Prodigy.

PNPscript PNPscript - ProdigyPNP's upcoming programming language, designed for hacking Prodigy. THIS IS IN EARLY DEVELOPMENT. DON'T BOTHER TRYING TO A

Prodigy P-NP 2 Sep 10, 2022
Library to change Android launcher App Icon and App Name programmatically !

AppIconNameChanger Change Android App launcher Icon and App Name programmatically ! Download Demo APK from HERE Kindly use the following links to use

Prabhakar Thota 587 Dec 29, 2022
Food Recipe App is an app for collecting most of food recipe in one app

Food Recipe App is an app for collecting most of food recipe in one app

Heba Elsaid 10 Dec 25, 2022
Arjun Naik 1 Apr 16, 2022
Show worldwide headline. API/Glide library/recycler view/volley library/kotlin/xml/ chrome custom tabs

Show worldwide headline. API/Glide library/recycler view/volley library/kotlin/xml/ chrome custom tabs. -> you can click on headline and it will open an article of that news in the app(no need to go to chrome or any browser)

SUMIT KUMAR 5 Nov 28, 2022
A music picker library for React Native. Provides access to the system's UI for selecting songs from the phone's music library.

Expo Music Picker A music picker library for React Native. Provides access to the system's UI for selecting songs from the phone's music library. Supp

Bartłomiej Klocek 60 Dec 29, 2022
:movie_camera: Movie discovery app showcasing Android best practices with Google's recommended architecture: MVVM + Repository + Offline support + Android Architecture Components + Paging library & Retrofit2.

Popular Movies Stage 1 + Stage 2 Discover the most popular and top rated movies playing. Movies data fetched using themoviedb.org API. ✨ Screenshots M

Yassin AJDI 189 Nov 26, 2022
Utility Android app for generating color palettes of images using the Palette library. Written in Kotlin.

Palette Helper is a simple utility app made to generate color palettes of images using Google's fantastic Palette library. It's mostly a for-fun pet p

Zac Sweers 154 Nov 18, 2022