Pergunta

I'm new at Android development and I have a question.

I'm creating a notification for the user. That's all OK. The problem is that when I change the device language, my notification doesn't updates yourself. I don't know if there are any native method to do that on Android.

For now, my solution is: when creating the notification, I create a thread that verifies if the language has changed. If so, it updates my notification. The thread is stoped when the user cleans the notification.

So, I don't know if it's a good pratice, or if there's another whay to to that.

PS: The application has lots of strings.xml files to translate strings. I'm using Thread class to create the thread.

Thanks in advance and sry for the bad english!

Foi útil?

Solução

In your application class, you can keep reference of the Notification Ids currently showing along with their info. You can detect language change in onConfigurationChanged(Configuration newConfig) and update your notifications there.

public class App extends Application {
    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        //update your notifications there is no need for a Thread
    }
}

Another Solution (Real one)

Add Receiver for locale Change

public class MyReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        //retrieve the list of notifications
        //update them (no need for thread)
    }
}

Add to your manifest:

<receiver android:name="MyReceiver">
    <intent-filter>
        <action android:name="android.intent.action.LOCALE_CHANGED">
        </action>
    </intent-filter>
</receiver>

Outras dicas

Most likely I would not have understood your question correctly.

Since you has lots of strings.xml files to translate strings.
You only need to put them in the appropriate folders:

res/values-pt-rPT //For Portuguese Portugal
res/values-fr-rFR // For French France
res/values-fr-rCA // For French France Canada

And so on.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top