我如何检测我的电话语言是否已更改,例如可以通知我们的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)
请给我建议,我仍在学习,会努力的。谢谢。
服务停止时,我的协程泄漏了广播接收器。这是因为服务在回调完成之前停止。如何取消协程以让我注销收款人的方式?
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)