相关疑难解决方法(0)

Android:如何检测语言已更改手机设置

我如何检测我的电话语言是否已更改,例如可以通知我们的facebook应用程序: please wait, we preparing your language

我用myString = Locale.getDefault().getDisplayLanguage();在我的onCreate()

在我的 onCreate()

@Override
    public void onCreate(Bundle savedInstanceState) {
        String myString = Locale.getDefault().getDisplayLanguage();
        if(myString.equals("en"){
            ProgressDialog progressDialog = new ProgressDialog(getApplicationContext());
            progressDialog.setMessage("Please wait, we preparing your language");
            progressDialog.show();
            /*
            it will dismiss until the language has been prepared
             */
        }else{
            //do nothing
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

请给我建议,我仍在学习,会努力的。谢谢。

android locale

2
推荐指数
3
解决办法
4980
查看次数

协程在注销时注销接收者

服务停止时,我的协程泄漏了广播接收器。这是因为服务在回调完成之前停止。如何取消协程以让我注销收款人的方式?

Service像这样的作品:

class DataCollectorService : Service(){
    var job : Job? = null

    override fun onStartCommand(...){
        job = GlobalScope.launch {
            val location = async { wifiScanner.getCurrentLocation() }
            //other asynchronous jobs
            location.await() 
            //do something with location
        }
    }

    override fun onDestroy(){
         job?.cancel()
    }
}
Run Code Online (Sandbox Code Playgroud)

这是BroadcastReciever未在中正确注销 的类onDestroy

class WifiScanner(val context: ContextWrapper) {
    val wifiManager: WifiManager

    init {
        wifiManager = context.baseContext.getSystemService(Context.WIFI_SERVICE) as WifiManager
    }

    suspend fun getCurrentScanResult(): List<ScanResult> =
        suspendCoroutine { cont ->
            val wifiScanReceiver = object : BroadcastReceiver() …
Run Code Online (Sandbox Code Playgroud)

android kotlin kotlinx.coroutines

1
推荐指数
1
解决办法
412
查看次数

标签 统计

android ×2

kotlin ×1

kotlinx.coroutines ×1

locale ×1